UITextField、UITextView插入附件图片

2016-06-01  本文已影响815人  WeeverLu

使用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;
上一篇 下一篇

猜你喜欢

热点阅读