ios,swift2020. 1. 31. 10:44

[ios] swift NSMutableAttributedString color 부분변경방법

 

글자의 range만 정해서 색상을 변경하고 싶다면???

 

let attributedString = NSMutableAttributedString(string: "qwerqweqweqweqwe")

 

attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(red: 0/255, green: 202/255, blue: 93/255, alpha: 255/255), range: NSRange(location: 0, length: 3))

        self.mTvText.attributedText = attributedString

func addAttribute(_ name: NSAttributedString.Key, value: Any, range: NSRange)

key 와 value넣고. range 영역 설정해주면..된다 ..

 

 

 

Posted by thdeodls85