码迷,mamicode.com
首页 > 其他好文 > 详细

UIDatePicker应用 常用属性和方法

时间:2015-08-31 13:22:32      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 @property(strong,nonatomic)UIDatePicker * datepicker;
 5 -(void)UpdataTime;
 6 @end
 7 
 8 @implementation ViewController
 9 
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     // Do any additional setup after loading the view, typically from a nib.
13     self.datepicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(10, 100, 350, 100)];
14     self.datepicker.backgroundColor = [UIColor whiteColor];
15     self.datepicker.datePickerMode = UIDatePickerModeDateAndTime;
16     //设置地区,即显示的语言
17     self.datepicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"];
18     //设置当前日历
19     [self.datepicker setCalendar:[NSCalendar currentCalendar]];
20     //使得时间和系统同步
21     [self.datepicker setTimeZone:[NSTimeZone systemTimeZone]];
22     
23     [self.datepicker setDate:[NSDate date] animated:YES];
24     
25     [self.datepicker addTarget:self action:@selector(UpdataTime) forControlEvents:UIControlEventValueChanged];
26     [self.view addSubview:self.datepicker];
27     
28     
29 }
30 -(void)UpdataTime
31 {
32     [self.datepicker setDate:[NSDate date] animated:YES];
33 }
34 - (void)didReceiveMemoryWarning {
35     [super didReceiveMemoryWarning];
36     // Dispose of any resources that can be recreated.
37 }
38 
39 @end
View Code

1、常用属性

//设置pickerview的显示模式

self.datepicker.datePickerMode = UIDatePickerModeDateAndTime;

其中UIDatePickerModeCountDownTimer 是倒计时模式,需用到

countDownDuration这个属性

 

//设置地区,即显示的语言

self.datepicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"];

//设置当前日历

[self.datepicker setCalendar:[NSCalendar currentCalendar]];

//使得时间和系统同步

[self.datepicker setTimeZone:[NSTimeZone systemTimeZone]];

//

date属性可读可写,可以从pickerview上读取数据显示到其他上面

//目标动作回调,实时监听数据更新

[self.datepicker addTarget:self action:@selector(UpdataTime) forControlEvents:UIControlEventValueChanged];

 

2、方法

//设置时间

self.datepicker setDate:[NSDate date] animated:YES];

UIDatePicker应用 常用属性和方法

标签:

原文地址:http://www.cnblogs.com/ylg-----/p/4772808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!