[英]How do you remove and replace an NSTextAttachment in an NSAttributedString
I have a mutable attributed string which I have added an image text attachment to. 我有一个可变的属性字符串,我添加了图像文本附件。
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 do i now get at that text attachment & replace it with a string at the location where the image is supposed to be located in the body of the text? 我现在如何获取该文本附件并将其替换为图像应位于文本正文中的位置的字符串?
只需告诉文本存储,您更新了相应附件字符范围的属性:
textStorage.edited([.EditedAttributes], range: range, changeInLength: 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.