Add attributes to an already attributed string in textView

385 Views Asked by At

I tried all the best to search all possible solution to get this to work. I am wondering if I can change the already attributed text to a new attributed text with other attributes without changing it to string.

 func updateSelectedText(attributes: [NSAttributedString.Key : Any]) {


let selectedRange = textView.selectedRange

let mutableAttributesString = NSMutableAttributedString(attributedString: textView.attributedText)
mutableAttributesString.setAttributes(attributes, range: selectedRange)

    print(attributes)
    print(selectedRange)
    print(mutableAttributesString)

}
0

There are 0 best solutions below