From the API I get text containing HTML теги and картинки . How to display them correctly. I tried using NSAttributedString , but this is not what I need. And what is it to display, in UILabel or in WebView ?
IOS 9, Swift 3 platform
If you want to display pictures, then UILabel will not help you, since inside you can only display text. Use UIWevView .
webView.loadHTMLString(htmlString, baseURL: nil) I did it without WebView
In Info.plist made permission to http:
App Transport Security Settings -> Allow Arbitrary Loads -> YES
And this code earned:
DispatchQueue.main.async { let attrStr = try! NSAttributedString( data: (self.detailLabelText?.data(using: String.Encoding.unicode, allowLossyConversion: true)!)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) self.detailLabel.attributedText = attrStr self.detailLabel.textAlignment = NSTextAlignment.justified self.detailLabel.contentMode = .scaleToFill self.detailLabel.font = UIFont(name: "PTSans-Narrow", size: 18.0) } detailLabel.adjustsFontSizeToFitWidth = true detailLabel.sizeToFit() Source: https://ru.stackoverflow.com/questions/624026/
All Articles