UITextField、UITextView插入附件图片

使用NSTextAttachment

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:self.textView.attributedText];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
textAttachment.image = [UIImage imageNamed:@"sky.png"];
NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
[string insertAttributedString:textAttachmentString atIndex:index];//index为用户指定要插入图片的位置
self.textView.attributedText = string;

你可能感兴趣的:(UITextField、UITextView插入附件图片)