I have the following code that sets up a UIDatePicker to show only time. I have two of these UIDatePickers displaying and I want to use them to allow the user to select a time range e.g. between 7 am and 5 pm.
UIDatePicker *datePicker=[[UIDatePicker alloc]init];
datePicker.frame=CGRectMake(-20, 0, 180, 200);
datePicker.datePickerMode = UIDatePickerModeTime;
[datePicker setMinuteInterval:0];
[datePicker setTag:1];
How can I set up the UIDatePicker so that it only shows hours and no minutes?
UIDatePicker isn’t that customizable. You’ll need to set up your own UIPickerView containing the time range you’re looking for. To fit the user’s date/time settings, you should use NSDateComponents and NSDateFormatter to get names for the hours that you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With