[置顶] iOS 控件之 UIDatePicker

发布时间:2016-12-11 16:00:38 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"[置顶] iOS 控件之 UIDatePicker",主要涉及到[置顶] iOS 控件之 UIDatePicker方面的内容,对于[置顶] iOS 控件之 UIDatePicker感兴趣的同学可以参考一下。

这是一个日期选择器 创建并设置一个日期选择器 _datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(20, 30, 0, 0)]; _datePicker.datePickerMode = UIDatePickerModeDate; [_datePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged]; NSLocale * local = [NSLocale systemLocale]; _datePicker.locale = local; NSCalendar * calendar = [NSCalendar autoupdatingCurrentCalendar]; _datePicker.calendar =calendar; NSTimeZone * zone = [NSTimeZone systemTimeZone]; _datePicker.timeZone = zone; NSDate * dater = [NSDate date]; //设置默认显示的最小日期 _datePicker.date =dater; _datePicker.minimumDate =[dater earlierDate:[NSDate dateWithTimeIntervalSince1970:99999 ]]; //设置最大日期 _datePicker.maximumDate = [dater laterDate:[NSDate dateWithTimeInterval:999999 sinceDate:[NSDate date]]]; [self.view addSubview:_datePicker];绑定事件-(void)datePickerChanged:(UIDatePicker*)pocker{ [pocker setDate:pocker.date animated:YES]; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateStyle:NSDateFormatterFullStyle]; NSString * stringDate = [dateFormatter stringFromDate:pocker.date]; NSLog(@"\ndate-->%@\n",stringDate); NSArray * dateArray = [stringDate componentsSeparatedByString:@","]; NSArray * month = [[dateArray objectAtIndex:1]componentsSeparatedByString:@" "]; NSLog(@"星期是:%@\n",[dateArray objectAtIndex:0]); NSLog(@"月份是:%@\n",[month objectAtIndex:1]); NSLog(@"日 是:%@\n",[month objectAtIndex:2]); NSLog(@"年份是:%@\n",[dateArray objectAtIndex:2]); } 控制台输出: date-->Tuesday, March 4, 2014 2014-02-20 17:32:38.836 ControlDemo[2237:70b] 星期是:Tuesday 2014-02-20 17:32:38.837 ControlDemo[2237:70b] 月份是:March 2014-02-20 17:32:38.837 ControlDemo[2237:70b] 日 是:4 2014-02-20 17:32:38.837 ControlDemo[2237:70b] 年份是: 2014

上一篇:Hadoop: the definitive guide 第三版 拾遗 第十二章 之Hive分区表、桶
下一篇:android中的事件类型分为按键事件和屏幕触摸事件

相关文章

相关评论