项目介绍:
UIPikerView时间选择器,自定义控件,选中颜色变化,取消和确定选中时间。开始进入选择器选中时间等操作!代理方法和控件代理及可实现
主要集成代码如下:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h" #import "XMRTimePiker.h" #define selfBacground [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0] #define selfHeight [UIScreen mainScreen].bounds.size.height @interface ViewController ()<XMRTimePikerDelegate>{ UIButton * _time_button; NSString * _time; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton * button=[UIButton buttonWithType:UIButtonTypeSystem]; self.view.backgroundColor=selfBacground; button.frame=CGRectMake(0,selfHeight-109,320, 50); [button setTitle:@"点击" forState:UIControlStateNormal]; [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; _time_button=[UIButton buttonWithType:UIButtonTypeSystem]; _time_button.backgroundColor=[UIColor greenColor]; [_time_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _time_button.frame=CGRectMake(0,selfHeight-159,320, 50); [_time_button addTarget:self action:@selector(Timeclick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_time_button]; } -(void)click{ XMRTimePiker *piker=[[XMRTimePiker alloc]init]; piker.delegate=self; [piker showTime]; } -(void)XMSelectTimesViewSetOneLeft:(NSString *)oneLeft andOneRight:(NSString *)oneRight andTowLeft:(NSString *)towLeft andTowRight:(NSString *)towRight{ _time=[NSString stringWithFormat:@"%@:%@-%@:%@",oneLeft,oneRight,towLeft,towRight]; [_time_button setTitle:_time forState:UIControlStateNormal]; } -(void)Timeclick:(UIButton*)bnt{ if (_time.length!=0) { NSArray * text_arr=[_time componentsSeparatedByString:@"-"]; NSString * star_str=text_arr[0]; NSString * end_str=text_arr[1]; NSArray * star_arr=[star_str componentsSeparatedByString:@":"]; NSArray * end_arr=[end_str componentsSeparatedByString:@":"]; XMRTimePiker *timeView = [[XMRTimePiker alloc] init]; timeView.delegate = self; [timeView SetOldShowTimeOneLeft:star_arr[0] andOneRight:star_arr[1] andTowLeft:end_arr[0] andTowRight:end_arr[1]]; [timeView showTime]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
DEMO 直接下载:
时间选择器.zip
(73.47 KB, 下载次数: 322, 售价: 10 金钱)
2016-7-25 15:23 上传
点击文件名下载附件
时间选择器