例如我必须把一个字符串“你好,世界!”在UIButton
。属性文本的颜色如何继承父级颜色?
而且“你好,”和“世界!”应该是不同的颜色。
“你好,”默认颜色为UIButton
,“世界!”有由NSMutableAttributedString
定制的颜色。
我再次解释代码和结果。
// Using a library `SwiftyAttributes`(https://github.com/eddiekaiger/SwiftyAttributes)
button.attributedText = "Hello, ".withJust() + "world!".withTextColor(.red)
button.setTitleColor(.black, for: .normal)
我想:你好,(黑色)世界(红色)
button.setTitleColor(.red, for: .normal)
我想:!你好,(红)世界(红色)
button.setTitleColor(.blue, for: .normal)
我想要:你好,(蓝色)世界!
但始终结果是:你好,(黑色)世界(红色)
...
也许我想的NSMutableAttributedString
默认颜色的优先级高于UIButton
默认颜色高。
但是,我可以看到我想要的结果吗?