예를 들어, "Hello, world!"문자열을 넣어야합니다. UIButton
속성이 지정된 텍스트의 색이 부모 색을 상속하는 방법은 무엇입니까?
"안녕하세요"및 "세계!" 다른 색상이어야합니다.
"Hello"의 기본 색상은 UIButton
이며 "world!" 사용자 정의 색상은 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
기본 색상보다라고 생각합니다.
하지만 원하는 결과를 볼 수 있습니까?