开发者

Disable Past Date in UIDatePicker in IPhone Objective C

I am new to Objective C and IPhone development.

I am using a UIDatePicker in my IPhone Application and my requirement is to allow the user to choose the future date only from the DatePicker.

To do this i want 开发者_如何学Cto disable past date & time in DatePicker only instead of putting a compare validation in the code.

Is this possible or there is an option to disable the past date in the DatePicker control itself.


Did you try this

[picker setMinimumDate: [NSDate date]];


Use the following line,to disable the previous dates of an UIDatePicker.

[picker setMinimumDate: [NSDate date]];

The current date is displayed as shown below

Disable Past Date in UIDatePicker in IPhone Objective C


For Swift :

let todaysDate = Date()

datePicker.minimumDate = todaysDate

It will not let the user to pick a date older than Today

OR

Or, if you want to reduce the code, use following way:

datePicker.minimumDate = Date()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜