Set the font for UIDatePicker in iOS10 with Swift

2019-06-11 15:07发布

问题:

Is there is a public interface to set the font for a UIDatePicker in Swift 3?

I am well aware that similar questions have been asked, mainly asking about how to change the color of labels inside a UIDatePicker.

Using something like datePicker.setValue(UIColor.someColor, forKey: "textColor") is accessing a private property, which could raise some eyebrows.

And using appearanceWhenContainedIn doesn't expose neither the label's textColor nor its font:

UILabel.appearance(whenContainedInInstancesOf: [UIDatePicker.self]).???

So, is there a formal way of changing the font of a UIDatePicker? Or should I build a date picker from scratch?

回答1:

So, is there a formal way of changing the font of a UIDatePicker?

No, there isn't. That is exactly why all these workarounds are proposed.