Reputation: 99
How do set the text in a Picker control to a light color for iOS13 darkmode
To support DARKMODE on IOS13 you need to set the text color to a colour that the system can change. But on the inspector, there is no ability to set the Picker text to any color.
There must be a simple way to do this but I cannot find it. Using Attributed text is NOT the solution.
Upvotes: 2
Views: 1368
Reputation: 461
I have used "UIColor.label" for "NSAttributedString.Key.foregroundColor".
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
if #available(iOS 13.0, *) {
return NSAttributedString(string: "ABC", attributes: [NSAttributedString.Key.foregroundColor: UIColor.label])
} else {
// Fallback on earlier versions
return NSAttributedString(string: "ABC", attributes: [NSAttributedString.Key.foregroundColor: UIColor.black])
}
}
Upvotes: 1
Reputation: 9
In storyboard, select the Attribute Inspector / View / Tint / Label Color :
That will make the font:
Upvotes: 0
Reputation: 99
Changing the Tint colour made no difference but I noticed that the font was different to everything else - that made me suspicious that the font was being set somewhere and I have found the answer. In the picker-view functions that are part of the delegate support for picker controls, there is a font setting that includes its colour.
Upvotes: 0