Swift를 사용하여 UITextView의 텍스트 색상 일부를 변경하는 방법

1394 단어 SwiftiOS
NSMutable AttributedString을 사용하면 문자열의 일부를 간단하게 변경할 수 있습니다.
let attrText = NSMutableAttributedString(string: "rich text")
attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, 4))
textView.attributedText = attrText

위에서 설명한 대로 문자 색상을 변경하는 방법이지만 문자의 배경색(N S B a c kgroundColorAttributeName) 등을 변경할 수도 있습니다.
또 UIlabel과 UItextField도 같은 문자 장식을 할 수 있다.

좋은 웹페이지 즐겨찾기