在 iOS 13 暗模式下,我UIColor.link
用于两种情况:
- foregroundColor 颜色为
NSAttributedString
- 图标的色调
问题:虽然我UIColor.link
在这两种情况下都使用,但它们呈现为不同的颜色。渲染的NSAttributedString
颜色更深,我发现这种颜色在黑色背景下很难阅读。
代码NSAttributedString
if #available(iOS 13.0, *) {
linkAttributes[.foregroundColor] = UIColor.link
} else {
linkAttributes[.foregroundColor] = UIColor.blue
}
// .font is the only other attribute I set
let attStr = NSAttributedString(string: cardName, attributes: linkAttributes)
我在以编程方式实例化的 UIButton 子类中使用此属性字符串:
class ConditionButton: UIButton {
required init() {
super.init(frame: .zero)
configureOnce()
}
func configureOnce() {
self.titleLabel?.numberOfLines = 0
self.titleLabel?.lineBreakMode = .byWordWrapping
self.titleLabel?.font = labelFont
self.contentHorizontalAlignment = .left
}
// some more code that does self.setAttributedTitle(attributedString, for: .normal)
}
顶部的文本是UIButton
with的子类的一个难以阅读的标签NSAttributedString
,在底部,有一个易于阅读UIButton
的图像和tintColor = UIColor.link
为什么会这样,我怎样才能获得相同的可读颜色NSAttributedString
?