1

我有UITextView一个混合图像(as NSTextAttachment)和字符串。UITextView是不可选择的,所以我可以使用:

- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 

如何删除textAttachment方法中的?

4

1 回答 1

3

您可以使用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];
于 2016-06-21T18:35:39.170 回答