关闭

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

252人阅读 评论(0) 收藏 举报
分类:

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;

    

  /*编写自己的代码*/

    

    

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:32744次
    • 积分:1038
    • 等级:
    • 排名:千里之外
    • 原创:70篇
    • 转载:29篇
    • 译文:0篇
    • 评论:3条
    最新评论