How to remove and replace NSTextAttachment in NSAttributedString

I have a variable attribute string to which I have added an embedding of the image text.

NSMutableAttributedString* attributedString = [_textField.attributedText mutableCopy];

NSMutableDictionary* dict = [_homeFeedCommentsViewController.inputData.array_extraElements objectAtIndex:0];

NSNumber* indexObject = [NSNumber numberWithUnsignedLong:attributedString.length];

[dict setObject:indexObject forKey:@"LocationIndex"];

[attributedString insertAttributedString:imageAsAttributedString atIndex:attributedString.length];

How can I now get into this text attachment and replace it with a line in the place where the image is supposed to be in the text?

+4
source share
1 answer

Just tell the text repository that you updated the attributes for the range of your corresponding anchor symbol:

textStorage.edited([.EditedAttributes], range: range, changeInLength: 0)
+1
source

Source: https://habr.com/ru/post/1598298/


All Articles