@H_404_1@需求
App开发中经常会有日期选择(如生日、睡眠定时等)或者省市区选择等此类功能,通常UI中不会单独使用UI中的控件,而是在UIPickerVIEw的基础上增加一个取消和确定按钮
@H_404_1@特点
1、支持常见的选择型的数据格式
该控件集成了 yyyy-MM-dd、yyyy-MM、hh mm、省市级联、省市区级联、自定义数据源(2列)、自定义数据源(3列)等多种格式
2、即支持UITextFIEld又支持事件触发机制
3、即支持XIB也支持纯代码
@H_404_1@效果图
GitHub:XXPickerView
@H_404_1@集成
首先将XXPickerVIEw文件夹拖入到工程中
@H_404_1@纯代码(选择任意一种模式)
#import "VIEwController.h"#import "XXTextFIEld.h"#define random(r,g,b,a) [UIcolor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 Alpha:(a)/255.0]#define Randomcolor random(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))@implementation VIEwController- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; CGfloat x = 170; CGfloat wIDth = 178; CGfloat height = 30; CGfloat margin = 50; // 模式一 XXTextFIEld *textFIEld = [[XXTextFIEld alloc] init]; textFIEld.frame = CGRectMake(x,28,wIDth,height); textFIEld.mode = XXPickerviewmodeDate; textFIEld.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld]; // 模式二 XXTextFIEld *textFIEld2 = [[XXTextFIEld alloc] init]; textFIEld2.frame = CGRectMake(x,textFIEld.frame.origin.y + margin,height); textFIEld2.mode = XXPickerviewmodeYearandMonth; textFIEld2.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld2]; // 模式三 XXTextFIEld *textFIEld3 = [[XXTextFIEld alloc] init]; textFIEld3.frame = CGRectMake(x,textFIEld2.frame.origin.y + margin,height); textFIEld3.mode = XXPickerviewmodeHourAndMinute; textFIEld3.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld3]; // 模式四 XXTextFIEld *textFIEld4 = [[XXTextFIEld alloc] init]; textFIEld4.frame = CGRectMake(x,textFIEld3.frame.origin.y + margin,height); textFIEld4.mode = XXPickerviewmodeProvinceCity; textFIEld4.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld4]; // 模式五 XXTextFIEld *textFIEld5 = [[XXTextFIEld alloc] init]; textFIEld5.frame = CGRectMake(x,textFIEld4.frame.origin.y + margin,height); textFIEld5.mode = XXPickerviewmodeProvinceCityAreas; textFIEld5.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld5]; // 模式六 XXTextFIEld *textFIEld6 = [[XXTextFIEld alloc] init]; textFIEld6.frame = CGRectMake(x,textFIEld5.frame.origin.y + margin,height); textFIEld6.mode = XXPickerviewmodeDataSourceFor2Column; textFIEld6.dataSource = [dataSourceFor2Column mutablecopy]; textFIEld6.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld6]; // 模式七 XXTextFIEld *textFIEld7 = [[XXTextFIEld alloc] init]; textFIEld7.frame = CGRectMake(x,textFIEld6.frame.origin.y + margin,height);; textFIEld7.mode = XXPickerviewmodeDataSourceFor3Column; textFIEld7.dataSource = [dataSourceFor3Column mutablecopy]; textFIEld7.backgroundcolor = Randomcolor; [self.vIEw addSubvIEw:textFIEld7]; }@end
@H_404_1@XIB方式
1、绑定自定义类
2、拖线并设置模式
@interface VIEwController ()@property (weak,nonatomic) IBOutlet XXTextFIEld *textFIEld;@end@implementation VIEwController- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; _textFIEld.mode = XXPickerviewmodeDate;}@end
@H_404_1@事件方式
#import "VIEwController.h"#import "XXinputVIEw.h"@interface VIEwController ()@property (weak,nonatomic) XXinputVIEw *inputVIEw;@end@implementation VIEwController- (voID)vIEwDIDLoad { [super vIEwDIDLoad];}- (IBAction)showClicked:(ID)sender { [self.inputVIEw show];}- (XXinputVIEw *)inputVIEw { if (_inputVIEw == nil) { XXinputVIEw *inputVIEw = [[XXinputVIEw alloc] initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.wIDth,200) mode:XXPickerviewmodeDate dataSource:nil]; inputVIEw.hIDeSeparator = YES; inputVIEw.completeBlock = ^(Nsstring *dateString){ NSLog(@"selected data : %@",dateString); }; [self.vIEw addSubvIEw:inputVIEw]; self.inputVIEw = inputVIEw; } return _inputVIEw;}@end
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
总结以上是内存溢出为你收集整理的iOS自定义日期和数据源选择控件全部内容,希望文章能够帮你解决iOS自定义日期和数据源选择控件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)