簡體   English   中英

如何在NSAttributedString中刪除和替換NSTextAttachment

[英]How do you remove and replace an NSTextAttachment in an NSAttributedString

我有一個可變的屬性字符串,我添加了圖像文本附件。

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

我現在如何獲取該文本附件並將其替換為圖像應位於文本正文中的位置的字符串?

只需告訴文本存儲,您更新了相應附件字符范圍的屬性:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM