Ios 从UITextView中删除/删除NSTextAttachment
我有一个Ios 从UITextView中删除/删除NSTextAttachment,ios,uitextview,nstextattachment,Ios,Uitextview,Nstextattachment,我有一个UITextView,它将混合使用图像(如NSTextAttachment)和字符串。无法选择UITextView,因此我可以使用: - (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 如何删除方法中的textAttachment?您可以使用NSMutable
UITextView
,它将混合使用图像(如NSTextAttachment
)和字符串。无法选择UITextView
,因此我可以使用:
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange
如何删除方法中的
textAttachment
?您可以使用NSMutableAttributedString的replaceCharactersRange:withString:
删除附件(范围作为UITextViewDelegate
方法的参数):
您可以使用NSMutableAttributedString
的replaceCharactersRange:with字符串:
删除附件(范围作为UITextViewDelegate
方法的参数):
NSMutableAttributedString*mutableAttr=[[textView attributedText]mutableCopy];[mutableAttr ReplaceCharactersRange:带有字符串的范围:@”“;[textView setAttributedText:mutableAttr]代码>?太棒了!将此作为解决方案发布,我将接受它NSMutableAttributedString*mutableAttr=[[textView attributedText]mutableCopy];[mutableAttr ReplaceCharactersRange:带有字符串的范围:@”“;[textView setAttributedText:mutableAttr]代码>?太棒了!将此作为解决方案发布,我将接受它
//Retrieve the attributed string
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy];
//Remove the attachment
[mutableAttr replaceCharactersInRange:range withString:@""];
//Set the new attributed string
[textView setAttributedText:mutableAttr];