Maintaining custom attributes when replacing attribute text with a UITextView

I have an editable UITextView that loads with the String attribute. This String attribute is loaded by the user attributes set by the application. For this reason, I always add these custom attributes to the typingAttributes textView.

Whenever I type, it works as expected, the added text has custom attributes set, but whenever I use predictive sentences to replace a word, the whole word is set without custom attributes.

As far as I know, every time the attribute text is set programmatically, typingAttributes automatically cleared. Therefore, it seems that when choosing a predictive offer, the text is set programmatically, and for this reason I lose all my user attributes.

Is there any way around this?

+7
ios swift uitextview nsattributedstring
source share
1 answer

I had the same problem, and looking further, I found that there is no way to do this without a private API. However, you can work around this problem in some cases by overriding replaceCharactersInRange:withAttributedString: in the text view textStorage and reinserting your custom attributes there.

0
source share

All Articles