How do you use NSAttributedString?

后端 未结 15 1126
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:19

Multiple colours in an NSString or NSMutableStrings are not possible. So I\'ve heard a little about the NSAttributedString which was introduced wit

15条回答
  •  不知归路
    2020-11-22 04:54

    Super easy way to do this.

    let text = "This is a colorful attributed string"
    let attributedText = 
    NSMutableAttributedString.getAttributedString(fromString: text)
    attributedText.apply(color: .red, subString: "This")
    //Apply yellow color on range
    attributedText.apply(color: .yellow, onRange: NSMakeRange(5, 4))
    

    For more detail click here; https://github.com/iOSTechHub/AttributedString

提交回复
热议问题