일반적으로 여러 스타일로 텍스트를 표시해야하는 경우 사용
let text = "오늘 날씨는 어떤지\\n주변에 뭐가 있나\\n요즘 볼만한 영화는 뭐가 있는지"
let attributtedString = **NSMutableAttributedString**(string: text)
let w_range = (text as NSString).range(of: "날씨")
let p_range = (text as NSString).range(of: "주변")
let m_range = (text as NSString).range(of: "영화")
let color = UIColor.primary
attributtedString.addAttribute(.foregroundColor, value: color, range: w_range)
attributtedString.addAttribute(.foregroundColor, value: color, range: p_range)
attributtedString.addAttribute(.foregroundColor, value: color, range: m_range)
❖ 예시 1 - 텍스트뷰의 텍스트 내에 하이퍼링크 추가
let textView = UITextView()
let text = "이용약관을 확인해주세요"
let attributedString = NSMutableAttributedString(string: text)
let linkRange = (text as NSString).range(of: "이용약관")
let url = URL(string: "<https://www.whattodo.com/policy>")!
attributedString.addAttribute(.link, value: url, range: linkRange)
textView.attributedText = attributedString
textView.isEditable = false
<aside> 💡 UILabel은 위의 방식으로 하이퍼링크를 직접 지원하지는 않는다
</aside>
<aside> 💡 text as NSString 타입 캐스팅
</aside>
❖ 예시 2 - 정렬, 줄 간격 같은 단락 스타일 적용