When I try to load HTML with images into a UITextView, the images do not want to fit the width of the screen, they appear too large. Setting the width attribute for the IMG tag and using CSS does not seem to help.
Here is the code snippet:
var content = "<html><head><meta charset='utf-8'><title>«Первый поворот налево или направо?» Secrets of Lewis Hamilton's success</title><style>img {max-width: '100%'; width: '100%'; height: auto;}body{ color:red }</style></head><body><p>Sometimes his superiority is immediately noticeable - as with the breathtaking speed of entering the first turn at this year's Australian Grand Prix, and sometimes it is not so obvious.</p><p><img src='http://autosport.com.ru/files/feature/2018/06/29/ba7222d642a69863db32ec8e5d2e8b8f.jpg' alt='Lewis Hamilton © autosport.com'/>Lewis Hamilton</p>"
let htmlData = NSString(string: content).data(using: String.Encoding.unicode.rawValue)
let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]
let attributedString = try! NSAttributedString(data: htmlData!, options: options, documentAttributes: nil)
txtView.attributedText = attributedString