显示8年前的datepicker并在ios中锁定ui datepicker [英] showing datepicker 18 years back and lock the ui datepicker in ios

查看:104
本文介绍了显示8年前的datepicker并在ios中锁定ui datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my project i need to show the date picker 18 back and i need to lock the 80 years backs so how can i show those date in datepicker can any one help me to find here here am adding code my code i printed in log but i need to display on my datepicker so how can i display

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的日期设置为日期范围之间的日期,以便您的最终代码看起来像

Hi first of all minimum date must be 100 year back date and max date must be 18 year back date and then set pickerView's date to a date between range of dates so your final code will be looks like

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;

希望这会对你有所帮助。

Hopefully this will be helpful for you.

这篇关于显示8年前的datepicker并在ios中锁定ui datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆