如何在NSAttributedString中删除和替换NSTextAttachment

时间:2015-07-16 22:19:41

标签: ios uitextview nsattributedstring nsmutableattributedstring nstextattachment

我有一个可变的属性字符串,我已经添加了图像文本附件。

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];

我现在如何获得该文字附件&在图像应该位于文本正文的位置用字符串替换它?

1 个答案:

答案 0 :(得分:1)

只需告诉文本存储,您更新了相应附件字符范围的属性:

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