当前位置:网站首页>Delegation agreement, data source agreement and advanced view in view
Delegation agreement, data source agreement and advanced view in view
2022-06-11 05:46:00 【swindler.】
Delegation agreement in view 、 Data source protocol and advanced view
Some advanced views have complex functions , We need to separate these complex functions from the view itself , Done by other classes . Of course , These classes need to follow the protocol specified by the view .
- Relatively simple views —— Only the entrustment agreement is specified , Include UITextField and UITextView, The corresponding naming rule of the delegation agreement is **“ View name +Delegate”**
- For some complex views , At the same time, we formulate the delegation agreement and data source agreement , These views are in iOS Not many , There are mainly selectors (UIPickerView)、 Collection view (UICollectionView) And table view (UItableView) The corresponding data source protocol naming rules are View name +DataSourse)
In the field of software , There is a classic saying :“ Where there is input , You need to verify ”
1. Selectors
import UIKit
class ViewController: UIViewController{
var datePicker:UIDatePicker!
var label:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let screen = UIScreen.main.bounds
self.view.backgroundColor = .clear
// Add date selector
let datePickerWidth:CGFloat = 320
let datePickerHeight:CGFloat = 167
self.datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: datePickerWidth, height: datePickerHeight))
// Set simplified Chinese
self.datePicker.locale = NSLocale(localeIdentifier: "zh-Hans") as Locale
// Format date and time
self.datePicker.datePickerMode = .dateAndTime
self.view.addSubview(datePicker)
// Add tags
let labelHeight:CGFloat = 200
let labelWidth:CGFloat = 21
let labelTopView:CGFloat = 281
self.label = UILabel(frame: CGRect(x: (screen.size.width - labelWidth)/2, y: labelTopView, width: labelWidth, height: labelHeight))
self.label.text = " Please select a date :"
self.label.textAlignment = .center
self.label.textColor = .white
self.view.addSubview(self.label)
// add to button Button
let button = UIButton(type: .system)
let buttonHeight:CGFloat = 46
let buttonWidth:CGFloat = 30
let buttonTopView:CGFloat = 379
button.frame = CGRect(x: (screen.size.width - buttonWidth)/2, y: buttonTopView, width: buttonWidth, height: buttonHeight)
button.setTitle(" choice ", for: UIControl.State())
button.addTarget(self, action: #selector(onClick(_:)), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func onClick(_ sender:AnyObject){
let theDate:NSDate = self.datePicker.date as NSDate
// This property returns the selected time
let desc = theDate.description(with: NSLocale.current)
// This property returns localized date information
NSLog("the date picked is:%@", desc)// Log information
let dateFormatter:DateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss"
NSLog("the date formate is :%@", dateFormatter.string(from: theDate as Date))// Log information
self.label.text = dateFormatter.string(from: theDate as Date)
}
}
2. Collection view
UICollecltionViewFlowLayout Is a streaming layout manager , From left to right, from top to bottom
边栏推荐
- Activity start process record
- 【深入kotlin】 - Flow 进阶
- NDK learning notes (I)
- 袋鼠云数栈基于CBO在Spark SQL优化上的探索
- NDK learning notes (VI) Basics: memory management, standard file i/o
- [元数据]LinkedIn-DataHub
- 49. grouping of acronyms
- Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset
- Project - Smart City
- Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack
猜你喜欢

Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack

NDK learning notes (VII) system configuration, users and groups

袋鼠云数栈基于CBO在Spark SQL优化上的探索

NFC Development -- the method of using NFC mobile phones as access control cards (II)

"All in one" is a platform to solve all needs, and the era of operation and maintenance monitoring 3.0 has come

Basics of customized view

Big meal count (time complexity) -- leetcode daily question

NDK learning notes (12) native graphics API, using avilib to create an avi video player

Implementation of data access platform scheme (Youzu network)

NDK learning notes (13) create an avi video player using avilib+opengl es 2.0
随机推荐
使用Batch读取注册表
Share an RSA encryption and decryption tool class, including public key encryption, private key decryption, private key encryption, public key decryption, private key signature, public key verificatio
Multi threading tutorial (XXIV) cas+volatile
[go deep into kotlin] - flow advanced
Install Oracle Database
袋鼠雲數棧基於CBO在Spark SQL優化上的探索
【深入kotlin】 - Flow 进阶
NDK R21 compiles ffmpeg 4.2.2 (x86, x86_64, armv7, armv8)
Gilde failed to go to the listener to call back the reason record when loading the Gaussian blur image
qmake 实现QT工程pro脚本转vs解决方案
Write a list with kotlin
How to make lamps intelligent? How to choose single fire and zero fire intelligent switches!
YOLOv5的Tricks | 【Trick8】图片采样策略——按数据集各类别权重采样
Clojure installation of metabase source code secondary development
es-ik 安装报错
数据接入平台方案实现(游族网络)
修复Yum依赖冲突
SQLite installation and configuration tutorial +navicat operation
Metabase源码二次开发之Clojure 安装
MySQL circulates multiple values foreach, XML writing method