UIDatePicker

UIDatePicker(时间选择器)

  • 父类是UIControl
  • 使用场景:当用户选择日期的时候弹出UIDatePicker给用户选择。
  • UIDatePickerios6和ios7的区别:


    UIDatePicker_第1张图片
    UIDatePickerios6和ios7.png

UIDatePicker的类型--UIDatePickerMode

//时间模式:显示时分(PM/AM),例如下午6:53.显示为(6 | 53 | PM)
datePicker.datePickerMode =UIDatePickerModeTime;

//日期模式:显示年月日,例如2007年11月15日.显示为(November | 15 | 2007)
datePicker.datePickerMode = UIDatePickerModeDate;

//日期时间模式(全模式)
// Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
datePicker.datePickerMode = UIDatePickerModeDateAndTime;

//倒数计秒模式,例如1小时53分,显示为(1 | 53)
datePicker.datePickerMode = UIDatePickerModeCountDownTimer;

UIDatePicker一般用法

// 创建一个UIDatePicker
UIDatePicker *datePicker = [[UIDatePicker alloc] init];

// 设置日期模型
datePicker.datePickerMode = UIDatePickerModeDate;

// 设置地区,zh:中国
datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];

// 监听UIDatePicker的选中的日期
[datePicker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged];

UIDatePicker自身唯一方法

// 设置动画日期
- (void)setDate:(NSDate *)date animated:(BOOL)animated;

你可能感兴趣的:(UIDatePicker)