I have added a UIDatePicker from storyboard. By default picker shows me the date format as (October - 26 - 2017). But i want the format to be dispayed as (26 - 10 - 2017 ).I am not able to display date in this format on UIDatePicker.Please tell me how can i do this?
Asked
Active
Viewed 2,397 times
0
-
1Did you read the reference guide? – Desdenova Oct 26 '17 at 10:34
-
1This might be helpful https://stackoverflow.com/questions/12740423/how-to-display-picker-view-in-mm-dd-yy-format-in-ios-5-1 – Karthick Manoharan Oct 26 '17 at 10:34
-
Not an answer to your question, but a suggestion what to do with your issue. 1) UIDatePicker have two properties: `datePickerMode` of kind `UIDatePickerMode`. In your case, you need to set this property to `UIDatePickerModeDate`; and 2) `locale` of kind `NSLocale`. For best user experience, use locale familiar to the user. Do not force user, using date formats, not applicable to his locale. – dvp.petrov Oct 26 '17 at 11:00
-
But it the requirement of project.Designer has designed this way and i have to implement like this only – TechChain Oct 26 '17 at 11:03
1 Answers
1
You can't do this.
From Apple's documentation for: UIKit > Views and Controls > UIDatePicker
Appearance
The appearance of UIDatePicker is not customizable.
The only thing Apple allows you to change is the date picker mode, which is not what you want. To change the layout to "dd-mm-yyyy", you will need build your own customized picker.
The way I'd suggest going about this, is instead of using UiDatePicker, to use UIPicker. Then, create and assign to that picker a unique class, which inherits from UIPickerView. This way you can customize it exactly how you want. Here is a helpful link for how to get all dates between a range (which is how UIDatePicker() is populated) - Swift: Print all dates between two NSDate()

JarbingleMan
- 350
- 1
- 12