如何将 Picker 控件中的文本设置为 iOS13 暗模式的浅色
要在 IOS13 上支持 DARKMODE,您需要将文本颜色设置为系统可以更改的颜色。但是在检查器上,无法将 Picker 文本设置为任何颜色。
必须有一个简单的方法来做到这一点,但我找不到它。使用属性文本不是解决方案。
如何将 Picker 控件中的文本设置为 iOS13 暗模式的浅色
要在 IOS13 上支持 DARKMODE,您需要将文本颜色设置为系统可以更改的颜色。但是在检查器上,无法将 Picker 文本设置为任何颜色。
必须有一个简单的方法来做到这一点,但我找不到它。使用属性文本不是解决方案。
我为“NSAttributedString.Key.foregroundColor”使用了“UIColor.label”。
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])
}
}
更改 Tint 颜色没有任何区别,但我注意到字体与其他字体不同 - 这让我怀疑字体被设置在某个地方,我找到了答案。在作为对选取器控件的委托支持的一部分的选取器视图函数中,有一个包含其颜色的字体设置。