
这里添加代码我在日志中打印的代码,但我需要在我的datepicker上显示,以便我如何显示
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIDentifIEr: NSGregorianCalendar];NSDate * currentDate = [NSDate date];NSDateComponents * comps = [[NSDateComponents alloc] init];[comps setYear: -18];NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];[comps setYear: -100];NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];[comps release];self.datePickerVIEw.minimumDate = minDate;self.datePickerVIEw.maximumDate = maxDate;NSLog(@"minDate %@",minDate);NSLog(@"maxDate%@",maxDate);解决方法 首先,最短的日期必须是100年的回溯日期,最长的日期必须是18年的回溯日期,然后将pickerVIEw的日期设置为日期范围之间的日期,以便最终的代码看起来像
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIDentifIEr: NSGregorianCalendar];NSDate * currentDate = [NSDate date];NSDateComponents * comps = [[NSDateComponents alloc] init];[comps setYear: -18];NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];[comps setYear: -100];NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];[comps release];self.datePickerVIEw.minimumDate = minDate;self.datePickerVIEw.maximumDate = maxDate;self.datePickerVIEw.date = minDate;
希望这对你有所帮助.
总结以上是内存溢出为你收集整理的iphone – 显示18年前的datepicker并在ios中锁定ui datepicker全部内容,希望文章能够帮你解决iphone – 显示18年前的datepicker并在ios中锁定ui datepicker所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)