UNIQLO's new alarm app has a custom UIDatePicker
:
And i want to create my own custom UIDatePicker
.
I tried to change the appearance of the DatePicker, but looking for UI_APPEARANCE_SELECTOR
in the UIDatePicker
returns nothing.
Meaning that its not possible to change any values, as per the docs:
How can change my UIDatePicker
's appearance?
add this method in your implementation file
when you run your app it will display all the subviews of the datePicker on your console, just choose any index and modify them one by one
modify the viewDidLoad and insert this code
In this case i change the background color of index "0", "4", "11"
To change date picker color:
And to change font the only way I know is:
Create category
UIFont+System
and place this code insideThis will set as well fonts in another places in your app (replacing system font by your font).
It appears to be quite difficult to change the way a
UIDatePicker
appears.The example you provided, in my opinion, is a sophisticated customization of a simple
UIPickerView
with two columns and probably a simulated infinite scroll (as Apple does in the date picker, and it's quite simple to realize).You can change little of the
UIDatePicker
through theUIAppearance
proxy, as seen in this example:Using this piece of code at the start of the application (just try it) you can change the aspect of only a couple of the main components of the date picker.
Labels are impossible to customize (and this test code proves it); apparently they are changed in aspect every time you rotate a column, since they are put inside a custom
UITableView
controller.To fully change these appearances you should probably work with private APIs from Apple, that will eventually result in your app being rejected.
If you just need a custom hour-minute picker (as shown in your screenshot), the full customization of appearance is reachable only extending the
UIPickerView
class or assigning an appropriate delegate to aUIPickerView
instance.Through the
method on the delegate you can make the single element of the picker view appear the way you want. Then you will have to appropriately handle the data source to make the two components of the picker virtually infinite.
You should go through the UICatalog by Apple. It has all the methods in which a UIDatePicker can be used including the custom date picker method . Study this link developer.apple.com/library/ios/samplecode/UICatalog/ . Also they have implemented a standard switch and the navigation bar which is given in the latter.
A combination of 2
UITableViews
is the way to go.UITableView
is a subview ofUIScrollView
, so it handles the following eventand on getting the position, just scroll the table to the center using the following method
Hope this helps.
With iOS 5 the UIAppearance protocol was introduced, which lets you customize several UI elements. UIDatePicker happens to conform this protocol, so that is probably the easiest way to do this. That is, if you're willing to support only iOS 5 users. Matthew's option would probably the next best thing, which should also work with older iOS versions.