我有一个UITextView,它将包含图像(如NSTextAttachment)和字符串。UITextView是不可选的,所以我可以使用:
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 如何删除方法中的textAttachment?
发布于 2016-06-21 18:35:39
您可以使用replaceCharactersInRange:withString: of 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];https://stackoverflow.com/questions/37951812
复制相似问题