user3725924 user3725924 - 4 months ago 16
iOS Question

Disable / Enable UIDatepicker

Is there any disable/enable function in Xcode, i have already tried the hidden function but that really doesn't suit my needs. I'm trying to turn off my UIDatepicker if a uiswitch has been toggled and if it isn't toggled i want it shown. hiding this still outputs todays date to my mail composer. Is there anyway to do this?

Answer

Make sure you have a property (IBOutlet) for your UIDatepicker in your .h file then you can simply do like this:

DatePickerNamed.userInteractionEnabled = YES;
DatePickerName.userInteractionEnabled = NO;

In addition to that I also turn down the alpha value for buttons and switches, if I disable them, so there is also a visual feedback that they're inactive.

Comments