1
votes

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.

1

1 Answers

0
votes
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
}