iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 显示18年前的datepicker并在ios中锁定ui datepicker大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

在我的项目中,我需要显示日期选择器18,我需要锁定80年后,所以如何在datepicker中显示这些日期可以任何人帮我在这里找到 这里添加代码我在日志中打印的代码,但我需要在我的datepicker上显示,以便我如何显示 NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalen
在我的项目中,我需要显示日期选择器18,我需要锁定80年后,所以如何在datepicker中显示这些日期可以任何人帮我在这里找到
这里添加代码我在日志中打印的代码,但我需要在我的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所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。