gpt4 book ai didi

ios - 如何通过界面生成器在属性字符串中使用动态颜色?

转载 作者:行者123 更新时间:2023-11-28 19:25:55 24 4
gpt4 key购买 nike

根据 Implementing Dark Mode on iOS我们需要将 foregroundColor 属性设置为新的标签颜色。这是如何使用界面构建器完成的?

我尝试使用“文本颜色”选项并将颜色设置为 Developer->labelColor,但这没有用。

编辑:由于目前这是不可能的,我使用了这个解决方法:

override func viewDidLoad() {
// Support Dark Mode
if #available(iOS 13.0, *) {
let attributes = NSMutableAttributedString(attributedString: textView.attributedText!)
attributes.addAttribute(.foregroundColor, value: UIColor.label, range: NSRange(location: 0, length: attributes.mutableString.length))
textView.attributedText = attributes
}
}

最佳答案

您不能在 Interface Builder 中执行此操作。您必须在代码中设置 .foregroundColor 属性。

let mas = NSMutableAttributedString(string:s, attributes:[
.font:UIFont(name:"GillSans", size:15)!,
.foregroundColor:UIColor.label,
]

关于ios - 如何通过界面生成器在属性字符串中使用动态颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58052165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com