美文网首页
UITextField、UITextView插入附件图片

UITextField、UITextView插入附件图片

作者: WeeverLu | 来源:发表于2016-06-01 15:43 被阅读815次

使用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插入附件图片

      本文链接:https://www.haomeiwen.com/subject/jzuhdttx.html