0

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)

}
Mariela
  • 139
  • 1
  • 7
  • Do you want to clear out all of the previously set attributes for the selected range, or update already set attributes (while keeping other attributes for the string that maybe were not specified in your `updatedSelectedText`'s `attributes` parameter)? – Michael Dautermann Jan 07 '20 at 04:01
  • Yes I want to update the selected Range which is already attributed. the `attributes` parameter has all the attributes, I printed them out. – Mariela Jan 07 '20 at 05:11
  • 2
    Dont call `setAttributes(_:range:)`, call `addAttributes(_:range:)` then. – Larme Jan 07 '20 at 10:39

0 Answers0