我有UITextView
一个混合图像(as NSTextAttachment
)和字符串。UITextView
是不可选择的,所以我可以使用:
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange
如何删除textAttachment
方法中的?
我有UITextView
一个混合图像(as NSTextAttachment
)和字符串。UITextView
是不可选择的,所以我可以使用:
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange
如何删除textAttachment
方法中的?
您可以使用replaceCharactersInRange:withString:
删除NSMutableAttributedString
附件(您将范围作为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];