UIDatePicker 轮转日期选择器 时间选择器

UIDatePicker *timePic = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 46, ScreenW - 40, ScreenH/3-92)];

    _timePic = timePic;

    timePic.datePickerMode = UIDatePickerModeDate;

枚举值,可以根据需要更改

typedef NS_ENUM(NSInteger, UIDatePickerMode) {

    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)

} __TVOS_PROHIBITED;


中英文模式

    [timePic setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_Hans_CN"]];

    [timePic setCalendar:[NSCalendar currentCalendar]];

设置时区

    [timePic setTimeZone:[NSTimeZone localTimeZone]];

设置最大最小显示时间

    NSDateFormatter *formatter_minDate = [[NSDateFormatter alloc] init];

    [formatter_minDate setDateFormat:@"yyyy-MM-dd"];

    NSDate *minDate = [formatter_minDate dateFromString:@"2000-01-01"];

    formatter_minDate = nil;

    NSDate *maxDate = [NSDate date];

    [timePic setMinimumDate:minDate];

    [timePic setMaximumDate:maxDate];

    [view addSubview:timePic];

   一旦轮转器日期变动,回调用此方法;

    [timePic addTarget:self action:@selector(dataChange:) forControlEvents:UIControlEventValueChanged];


-(void)dataChange:(id)change{

    

    UIDatePicker *control = (UIDatePicker *)change;

    NSData *date = control.date;

    

  /*编写自己的代码*/

    

    

}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yiral/article/details/51537317
个人分类: UI基本控件的用法
上一篇base64 与 md5 以及 LaunchScreen.xib: Line 20: EntityRef: expecting ';'错误
下一篇汉字转换为拼音
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭