从JSON向文本字段添加图像

时间:2015-08-31 09:52:49

标签: xcode swift

我有一个文本字段,我使用JSON加载内容。我怎么还要添加图像?例如,如果我使用图像链接。

enter image description here

这就是我想要的方式。我希望能够在文本之间显示图片。

1 个答案:

答案 0 :(得分:0)

您必须创建一个json解析器并为每个图像创建一个NSTextAttachment

 let textAttachment = NSTextAttachment()
 textAttachment.image = yourImage
 let attrStringWithImage = NSAttributedString.init(attachment: textAttachment)
 attributedString.replaceCharactersInRange(NSMakeRange(6, 1), withAttributedString: attrStringWithImage)
 textView.attributedText = attributedString
相关问题