1

如何将 Picker 控件中的文本设置为 iOS13 暗模式的浅色

要在 IOS13 上支持 DARKMODE,您需要将文本颜色设置为系统可以更改的颜色。但是在检查器上,无法将 Picker 文本设置为任何颜色。

必须有一个简单的方法来做到这一点,但我找不到它。使用属性文本不是解决方案。

4

3 回答 3

1

我为“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])
        }
    }
于 2021-03-02T05:11:31.880 回答
0

更改 Tint 颜色没有任何区别,但我注意到字体与其他字体不同 - 这让我怀疑字体被设置在某个地方,我找到了答案。在作为对选取器控件的委托支持的一部分的选取器视图函数中,有一个包含其颜色的字体设置。

于 2019-09-11T07:01:14.170 回答
0

在情节提要中,选择Attribute Inspector / View / Tint / Label Color

在此处输入图像描述

这将使字体:

  • 白色,在黑暗模式下
  • 黑色,在灯光模式下
于 2020-04-21T19:36:52.027 回答