Swift change date picker language

Evgeniy Kleban picture Evgeniy Kleban · Nov 1, 2017 · Viewed 10.7k times · Source

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.

Answer

Ahmad F picture Ahmad F · Nov 1, 2017

You should assign loc to the date picker locale property:

let loc = Locale(identifier: "uk")
self.datePicker.locale = loc