I have the body (HTML with images) of a wordpress article obtained via JSON, I'm using a UITextView` to show it and everything works correctly, except that the image that contains the HTML only shows a part.
To format the HTML content, I use the following extension:
extension NSAttributedString {
convenience init?(html: String) {
guard let data = html.data(using: String.Encoding.unicode, allowLossyConversion: false) else {
return nil
}
guard let attributedString = try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) else {
return nil
}
self.init(attributedString: attributedString)
}
}
and to show it in the UITextView, I do it like this:
myTextView.attributedText = NSAttributedString(html: htmlString!)
In var htmlString
: HTML is stored.
All good, except that when loading the image of the HTML content it does not scale.
How could I make the HTML content images show autoscaling?
The html code of the images are similar to:
<img class="alignnone size-full wp-image-9667" src="https://.../wp-content/uploads/2016/02/image.jpg" alt="image" width="612" height="894">
CSS could be added?