Xcode 从JSON向文本字段添加图像
我有一个使用JSON加载内容的文本字段。我如何向其中添加图像?例如,如果我要使用图像链接Xcode 从JSON向文本字段添加图像,xcode,swift,Xcode,Swift,我有一个使用JSON加载内容的文本字段。我如何向其中添加图像?例如,如果我要使用图像链接 这是我想要的方式。我希望能够在文本之间显示图片。您必须为每个图像创建一个json解析器并创建一个NSTextAttachment: let textAttachment = NSTextAttachment() textAttachment.image = yourImage let attrStringWithImage = NSAttributedString.init(attachment:
这是我想要的方式。我希望能够在文本之间显示图片。您必须为每个图像创建一个json解析器并创建一个
NSTextAttachment
:
let textAttachment = NSTextAttachment()
textAttachment.image = yourImage
let attrStringWithImage = NSAttributedString.init(attachment: textAttachment)
attributedString.replaceCharactersInRange(NSMakeRange(6, 1), withAttributedString: attrStringWithImage)
textView.attributedText = attributedString
您必须为每个图像创建json解析器并创建
NSTextAttachment
:
let textAttachment = NSTextAttachment()
textAttachment.image = yourImage
let attrStringWithImage = NSAttributedString.init(attachment: textAttachment)
attributedString.replaceCharactersInRange(NSMakeRange(6, 1), withAttributedString: attrStringWithImage)
textView.attributedText = attributedString
请参阅此链接:。是否有其他方法?因为在这个答案中,你必须定义图像的位置。如果可能的话,我的目标是从同一个字段中获取包含JSON的内容。或者你可以将其嵌入UIView。这也没关系。我还了解到它可以与webview一起使用,但我如何嵌入它?你能发布你的JSON内容示例吗?请参考此链接:。是否有其他方法?因为在这个答案中,你必须定义图像的位置。如果可能的话,我的目标是从同一个字段中获取包含JSON的内容。或者你可以将其嵌入UIView。这也很好。我也读到它可以与webview一起工作,但我如何嵌入它?你能发布你的JSON内容示例吗?