如何在UItextview中插入NSAttributedString文本和图像GIF(自动播放)?

时间:2016-07-20 04:56:19

标签: ios swift swift2 uitextview

  

我使用NSAttributedString文本,并希望附件gif图像显示在UItextview

在mycode dostn下面为gif图像工作

let mytext = UITextview()
let result = NSMutableAttributedString()
let attachment = NSTextAttachment() 
attachment.image = UIImage(named:"abc.gif")
let attachmentString = NSAttributedString(attachment: attachment) 
let myString = NSMutableAttributedString(string:"")
myString.appendAttributedString(attachmentString) 
result.appendAttributedString(myString)
mytext.attrbutedText = result

请帮助解决附件gif图片 它会自动播放。 提前致谢

1 个答案:

答案 0 :(得分:-1)

嗨请试试这个:

 UIImageView * imageview =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"download.gif"]];
 NSMutableArray *exclutionPaths = [NSMutableArray array];
[exclutionPaths addObject:[UIBezierPath bezierPathWithRect:CGRectInset(imageview.frame, -4, 0)]];
[_textView.textContainer setExclusionPaths:exclutionPaths];
[_textView addSubview:imageview]; 
_textView.text=@"Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...Blah...";