第十三篇 - UIDatePicker
初始化
UIDatePicker *dateView = [[UIDatePicker alloc] init];
添加事件监听
[dateView addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
获取当前选中的时间
- (void)click:(UIDatePicker *)sender{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.timeZone = [NSTimeZone systemTimeZone];//系统所在时区
df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *systemTimeZoneStr = [df stringFromDate:sender.date];
NSLog(@"%@",systemTimeZoneStr);
}
以下来自:http://my.oschina.net/u/2340880/blog/464715
@property (nonatomic) UIDatePickerMode datePickerMode;
设置控件模式,枚举如下:
1
2
3
4
5
6
|
typedef NS_ENUM(NSInteger, UIDatePickerMode) { UIDatePickerModeTime, //时间模式,显示时分和上下午 UIDatePickerModeDate, //日期模式显示年月日 UIDatePickerModeDateAndTime, //时间和日期模式,显示月日星期,时分上下午 UIDatePickerModeCountDownTimer, //计时模式,显示时和分 }; |
@property (nonatomic, retain) NSLocale *locale;
设置本地化环境
@property (nonatomic, copy) NSCalendar *calendar;
设置日历
@property (nonatomic, retain) NSTimeZone *timeZone;
设置时区
@property (nonatomic, retain) NSDate *date;
设置当前时间
@property (nonatomic, retain) NSDate *minimumDate;
设置最小时间点
@property (nonatomic, retain) NSDate *maximumDate;
设置最大时间点
@property (nonatomic) NSTimeInterval countDownDuration;
只适用于计时模式,设置时间
@property (nonatomic) NSInteger minuteInterval;
设置每一格的时间差
- (void)setDate:(NSDate *)date animated:(BOOL)animated;
设置到一个时间,有动画效果