2016-06-21 1 views
-1

UITextView에는 이미지 (문자 :)와 문자열이 혼합되어 있습니다. UITextView 선택할 수 없습니다, 그래서 사용할 수 있습니다UITextView에서 NSTextAttachment 삭제/제거

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

어떻게 방법에 textAttachment을 삭제합니까?

+0

'NSMutableAttributedString * mutableAttr = [[텍스트 뷰 attributedText] mutableCopy]; [mutableAttr replaceCharactersInRange : range withString : @ ""]]; [textView setAttributedText : mutableAttr]; – Larme

+0

굉장해! 솔루션으로 게시하고 받아 들일 것입니다. – Gukki5

답변

1

당신은 첨부 파일을 제거하는 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]; 
관련 문제