gpt4 book ai didi

iphone - 显示 18 年前的 datepicker 并在 ios 中锁定 ui datepicker

转载 作者:可可西里 更新时间:2023-11-01 03:36:10 33 4
gpt4 key购买 nike

在我的项目中,我需要显示 18 年前的日期选择器,我需要锁定 80 年前的日期,所以我如何在日期选择器中显示这些日期,谁能帮我找到这里在这里添加代码我在日志中打印的代码但是我需要在我的日期选择器上显示所以我如何显示

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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853795/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com