how to append Attributed Text String with Attributed String in Swift

后端 未结 4 1345
天涯浪人
天涯浪人 2021-01-31 01:52

I want to append an Attributed Text with another Attributed Text in Swift. Please provide any sample code for appending operation of two attributed String in Swift.

4条回答
  •  别跟我提以往
    2021-01-31 02:29

    using extension,

    extension NSMutableAttributedString{
        func getAttributedStringByAppending(attributedString:NSMutableAttributedString) -> NSMutableAttributedString{
            let newAttributedString = NSMutableAttributedString()
            newAttributedString.append(self)
            newAttributedString.append(attributedString)
            return newAttributedString
        }
    }
    

    Usage: attributedString1, attributedString2 are two NSMutableAttributedString, then

    let combinedAttributedString = attributedString1.getAttributedStringByAppending(attributedString: attributedString2)
    

提交回复
热议问题