首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从NSTextAttachment中删除/删除UITextView

从NSTextAttachment中删除/删除UITextView
EN

Stack Overflow用户
提问于 2016-06-21 18:20:18
回答 1查看 2K关注 0票数 1

我有一个UITextView,它将包含图像(如NSTextAttachment)和字符串。UITextView是不可选的,所以我可以使用:

代码语言:javascript
复制
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 

如何删除方法中的textAttachment

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-21 18:35:39

您可以使用replaceCharactersInRange:withString: of NSMutableAttributedString来删除攻击(您获得了作为UITextViewDelegate方法参数的范围):

代码语言:javascript
复制
//Retrieve the attributed string
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy];
//Remove the attachment
[mutableAttr replaceCharactersInRange:range withString:@""]; 
//Set the new attributed string
[textView setAttributedText:mutableAttr];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37951812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档