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

    2 answers 2

    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) 
    • Pictures not showing - Zhan
    • So the problem is in the HTML code. Try to open your HTML code in the browser, and see if it shows pictures or not - Vitali Eller
    • App Transport Security Settings configured now opens - Zhan
    • If the answer helped, mark it as correct - Vitali Eller

    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()