Solution 1 :

func convertFromHTMLString(_ input: String?) -> NSAttributedString? {

    guard let input = input else { return nil }

    guard let data = input.data(using: String.Encoding.unicode, allowLossyConversion: true) else { return nil  }


    if let string = try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil).string
    {
        //Set color and font
        let myAttribute = [ NSAttributedString.Key.foregroundColor: UIColor.white , NSAttributedString.Key.font: UIFont(name: "Chalkduster", size: 17.0)!  ]
        let myAttrString = NSAttributedString(string: string, attributes: myAttribute)
        return myAttrString
    }


    return nil
}

Problem :

Hi guys I have small problem, I’m using func:

static func convertFromHTMLString(_ input: String?) -> NSAttributedString? {

        guard let input = input else { return nil }

        guard let data = input.data(using: String.Encoding.unicode, allowLossyConversion: true) else { return nil  }
        return try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil)
    }

to read my Strings from Localizable.strings with attributes like this:

String

But when I run my app it looks that:

App screen

This change my Label color to black and font size to something like 10-12 ;/
My Label should have white color and font size 17, anyone know how to fix it?
Thanks ! 🙂

@Edit1
The solution must look like this
Android version
This is how it looks on Android.

Comments

Comment posted by Szczowio

It change color and font size, but now don’t working and and this is most important for me ;/

Comment posted by Stefan

Send me example html like text

Comment posted by koen

You already asked about and earlier and that was marked a duplicate. Did you try the answer in the linked question?

Comment posted by Stefan

@Szczowio i try this var html = “n Nowy wspabiay swiat
n Aldous Huxley

n Exampleeee ” wrok correctly

Comment posted by Szczowio

@koen That’s true. I realized answer from my lasy question who you linked me but now I have this problem, I have tried to find solution in internet, forums, Facebook and nothing ;o This is horrible important for me to find the solution. #Stefan I can’t put it to var, because I have something like 500 strings, that’s why I must have it in Localizable.strings, when I tried have it on var It still work the same and cut my String I don’t know why ;/ #Edit1 I added how it should look in solution from my Android project, on iOS I must look the same.

By