9

I want to change format of month represent in my UIDatePicker. I tried:

self.datePicker = UIDatePicker()
self.datePicker.backgroundColor = .white
self.datePicker.datePickerMode = .date
let loc = Locale.init(identifier: "uk")
var calendar = Calendar.current
calendar.locale = loc
self.datePicker.calendar = calendar

After that, month representation suppose to be in ukranian, but it still in other language.

Ahmad F
  • 28,447
  • 13
  • 87
  • 133
Evgeniy Kleban
  • 6,532
  • 12
  • 46
  • 99
  • Did you try directly setting the picker's `locale` property instead of the calendar's `locale` property? – rmaddy Nov 01 '17 at 14:07

1 Answers1

28

You should assign loc to the date picker locale property:

let loc = Locale(identifier: "uk")
self.datePicker.locale = loc
Ahmad F
  • 28,447
  • 13
  • 87
  • 133
  • Thanks for your answer, do you know way to change global locale so that each formatter would use it? – えるまる Jan 29 '20 at 08:14
  • @Erumaru https://stackoverflow.com/questions/26252233/global-constants-file-in-swift https://iosdevcenters.blogspot.com/2015/12/how-to-define-global-constant-in-swift.html https://medium.com/swift-india/defining-global-constants-in-swift-a80d9e5cbd42 – Ahmad F Jan 29 '20 at 09:15