with iOS 13 dark mode, I use UIColor.link
for two cases:
- foregroundColor color for
NSAttributedString
- tint color for icons
problem: though I use UIColor.link
in both cases, they render as different colors.
The color rendered for NSAttributedString
is darker and I find this color really hard to read over a black background.
code for 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)
I use this attributed string in a UIButton subclass that I instantiate programmatically:
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)
}
The text at the top is a hard to read label of a subclass of UIButton
with NSAttributedString
, at the bottom, there is an easy to read UIButton
with an image and tintColor = UIColor.link
Why is that and how can I get the same readable color for NSAttributedString
?