For example I have to put a String "Hello, world!" in the UIButton
.
And "Hello," and "world!" should be different colors.
"Hello," has the default color of UIButton
, and "world!" has the customized color by NSMutableAttributedString
.
I explain again with code and result.
// Using a library `SwiftyAttributes`(https://github.com/eddiekaiger/SwiftyAttributes)
button.attributedText = "Hello, ".withJust() + "world!".withTextColor(.red)
button.setTitleColor(.black, for: .normal)
I want: Hello,(black) world!(red)
button.setTitleColor(.red, for: .normal)
I want: Hello,(red) world!(red)
button.setTitleColor(.blue, for: .normal)
I want: Hello,(blue) world!(red)
But always the result is: Hello,(black) world!(red)
...
Maybe I think the priority of NSMutableAttributedString
default color is higher than UIButton
default color.
But can I see the result I want?