[英]Delete / Remove NSTextAttachment from UITextView
我有一個UITextView
,它將包含圖像(如NSTextAttachment
)和字符串的混合。 UITextView
是不可選擇的,因此我可以使用:
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange
如何在方法中刪除textAttachment
?
您可以使用NSMutableAttributedString
replaceCharactersInRange:withString:
刪除附件(您將范圍作為UITextViewDelegate
方法的參數):
//Retrieve the attributed string
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy];
//Remove the attachment
[mutableAttr replaceCharactersInRange:range withString:@""];
//Set the new attributed string
[textView setAttributedText:mutableAttr];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.