<强>需求强>
应用开发中经常会有日期选择(如生日,睡眠定时等)或者省市区选择等此类功能,通常UI中不会单独使用UI中的控件,而是在UIPickerView的基础上增加一个取消和确定按钮
<>强特点强>
1支持常见的选择型的数据格式
该控件集成了yyyy-MM-dd yyyy-MM, hh mm,省市级联,省市区级联,自定义数据源(2列),自定义数据源(3列)等多种格式
2,即支持UITextField又支持事件触发机制
3,即支持XIB也支持纯代码
<>强效果图强>
GitHub: XXPickerView
<强>集成强>
首先将XXPickerView文件夹拖入到工程中
<强>纯代码(选择任意一种模式)强>
#进口“ViewController.h” #进口“XXTextField.h” #定义随机(r, g, b, a)(用户界面颜色colorWithRed:格林(r)/255.0: 255.0 (g)/蓝色:(b)/255.0 alpha: (a)/255.0) #定义RandomColor随机(arc4random_uniform (256), arc4random_uniform (256), arc4random_uniform (256), arc4random_uniform (256)) @ implementation ViewController - (void) viewDidLoad { (超级viewDidLoad); CGFloat x=170; CGFloat宽度=178; CGFloat高度=30; CGFloat保证金=50;//模式一 XXTextField * textField=[[XXTextField alloc] init); textField.frame=CGRectMake (x, 28岁的宽度、高度); 文本框。模式=XXPickerViewModeDate; 文本框。写成backgroundColor=RandomColor; (自我。视图addSubview:文本框);//模式二 XXTextField * textField2=[[XXTextField alloc] init); textField2.frame=CGRectMake (x, textField.frame.origin.y +利润,宽度、高度); textField2。模式=XXPickerViewModeYearAndMonth; textField2。写成backgroundColor=RandomColor; (自我。视图addSubview textField2):;//模式三 XXTextField * textField3=[[XXTextField alloc] init); textField3.frame=CGRectMake (x, textField2.frame.origin.y +利润,宽度、高度); textField3。模式=XXPickerViewModeHourAndMinute; textField3。写成backgroundColor=RandomColor; (自我。视图addSubview textField3):;//模式四 XXTextField * textField4=[[XXTextField alloc] init); textField4.frame=CGRectMake (x, textField3.frame.origin.y +利润,宽度、高度); textField4。模式=XXPickerViewModeProvinceCity; textField4。写成backgroundColor=RandomColor; (自我。视图addSubview textField4):;//模式五 XXTextField * textField5=[[XXTextField alloc] init); textField5.frame=CGRectMake (x, textField4.frame.origin.y +利润,宽度、高度); textField5。模式=XXPickerViewModeProvinceCityAreas; textField5。写成backgroundColor=RandomColor; (自我。视图addSubview textField5):;//模式六 XXTextField * textField6=[[XXTextField alloc] init); textField6.frame=CGRectMake (x, textField5.frame.origin.y +利润,宽度、高度); textField6。模式=XXPickerViewModeDataSourceFor2Column; textField6。数据源=[dataSourceFor2Column mutableCopy]; textField6。写成backgroundColor=RandomColor; (自我。视图addSubview textField6):;//模式七 XXTextField * textField7=[[XXTextField alloc] init); textField7.frame=CGRectMake (x, textField6.frame.origin.y +利润,宽度、高度);; textField7。模式=XXPickerViewModeDataSourceFor3Column; textField7。数据源=[dataSourceFor3Column mutableCopy]; textField7。写成backgroundColor=RandomColor; (自我。视图addSubview textField7):; } @endiOS自定义日期和数据源选择控件