0

I want to make a simple TimePicker like this :

enter image description here

If I use UITableView then how do I know that middle row/cell is selected ? Also the last row/cell will never be in middle. Apart from that, It has to be two tableViews as both hour selection and minute selection needs to be separate. If I use two scrollViews , still how to figure out when an item is exactly in the middle and should be considered as selected item.

I could not find any customization options in the default date time picker. Secondly , my picker is very simple one, yet I am not able to find a proper method to create this type of picker. I cannot use the default picker, because it has different design which is not what I want.

Any help is appreciated. Thanks

intellignt_idiot
  • 1,962
  • 2
  • 16
  • 23
  • First of all, forget about tableviews for this. You need to use a UIPicker with 2 columns as in the answer below. See this link also http://stackoverflow.com/questions/3806517/how-do-i-add-multiple-components-to-a-pickerview You then have an array of hours & mins populating each component of the picker. – Devster101 May 24 '16 at 13:51
  • but then, what about the design ?Is it customizable ? The problem is that I can't use the default picker. And I need to have the same design as show in the image above. That is the problem. Please read the question, what exactly I am trying to say. – intellignt_idiot May 24 '16 at 14:14

2 Answers2

2

If I understand you right, you want only time in your picker and design it? From storyboard you can select wheather it is "Time", "Date", "Date & time" etc. Just slect your picker and from right select attributes.

enter image description here

But for design I suggest you to try these lines of codes:

datePicker.backgroundColor = UIColor.whiteColor() //It is for background color

datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")//It is for text color

self.datePicker.performSelector("_setHighlightColor:", withObject:Constants.Colors.mainHeaderColor) //This should be higlight color

And I suggest you to read this topic.

Community
  • 1
  • 1
Tarvo Mäesepp
  • 4,477
  • 3
  • 44
  • 92
  • I have been able to design the required time picker with your answer's help. Thanks to you @Tarvo There is one small thing I am still stuck at. It is the the selection cell, it has two lines one at the top and one at the bottom. Even I have put my custom view over it, they are still seen and I do not know how to remove the default selection view (the two lines at the top and bottom of the selected item). Do you know if that is possible to remove those lines ? – intellignt_idiot May 25 '16 at 08:08
0

Apple have a specific picker specifically for dates and times.

let picker = UIDatePicker()
picker.datePickerMode = UIDatePickerMode.Time
torinpitchers
  • 1,282
  • 7
  • 13