IOS控件 UIDatePicker
效果
初始化
UIDatePicker *pick = [[UIDatePicker alloc] init];
属性
1. 模式
pick.datePickerMode = UIDatePickerModeTime;
可写属性有
UIDatePickerModeTime, // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM) UIDatePickerModeDate, // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007) UIDatePickerModeDateAndTime, // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM) UIDatePickerModeCountDownTimer, // Displays hour and minute (e.g. 1 | 53)
监听
1. 添加监听
[pick addTarget:self action:@selector(setTimeOK:) forControlEvents:UIControlEventValueChanged];
2. 实现监听
- (void)setTimeOK:(UIDatePicker *)sender{ NSDate *date = sender.date; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *dateStr = [formatter stringFromDate:date];
self.textField.text = [NSString stringWithFormat:@"%@", dateStr];
}
typedef enum { NSDateFormatterNoStyle = kCFDateFormatterNoStyle, NSDateFormatterShortStyle = kCFDateFormatterShortStyle,//“11/23/37” or “3:30pm” NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,//\"Nov 23, 1937\" NSDateFormatterLongStyle = kCFDateFormatterLongStyle,//\"November 23, 1937” or “3:30:32pm\" NSDateFormatterFullStyle = kCFDateFormatterFullStyle//“Tuesday, April 12, 1952 AD” or “3:30:42pm PST” } NSDateFormatterStyle;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。