簡體   English   中英

從UITextView刪除/刪除NSTextAttachment

[英]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.

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