gpt4 book ai didi

ios - 从 UITextView 中删除/删除 NSTextAttachment

转载 作者:行者123 更新时间:2023-11-28 21:26:28 32 4
gpt4 key购买 nike

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

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

如何删除方法中的textAttachment

最佳答案

您可以使用 NSMutableAttributedStringreplaceCharactersInRange:withString: 删除附件(您将范围作为 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];

关于ios - 从 UITextView 中删除/删除 NSTextAttachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37951812/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com