Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Only Hours In UIDatePicker

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?

like image 757
motionpotion Avatar asked Oct 02 '22 05:10

motionpotion


1 Answers

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.

like image 182
Noah Witherspoon Avatar answered Nov 23 '22 00:11

Noah Witherspoon