NSDatePicker的使用(设置日期范围)

2021-10-29 11:01:30 浏览数 (3)

设置日期期限的时候下面这个方法用不了(升级成ios7之后)

 NSDate *toDate =[[NSDate alloc]initWithString:@"2000-10-10 12:00:00 -0500"];

用下面的方法替换

代码语言:javascript复制
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];

[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString * mindateStr = @"1900-01-01 00:00:00";

NSString * maxdateStr = @"2099-01-01 00:00:00";

NSDate * mindate = [formatter dateFromString:mindateStr];

NSDate * maxdate = [formatter dateFromString:maxdateStr];

datepiker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 40, 320, 180)];

datepiker.datePickerMode = UIDatePickerModeDate;//设置日期显示格式

datepiker.minimumDate = mindate;

datepiker.maximumDate = maxdate;

datepiker.backgroundColor = [UIColor  whiteColor];</pre> 

0 人点赞