I am trying to add letter spacing on a particular text. Big text coming from the server with HTML tags and I need letter spacing only where is P tag. but other than letter-spacing everything works. Am I missing something? Is there a way of doing this with attributed text, or will this need to be resolved with another solution? I currently have tried the following as an example:
let htmlCSSString = "<style>" +
"html *" +
"{" +
"font-size: 15px !important;" +
"font-family: Arial !important;" +
"text-align: justify;" +
"line-height: 1.5;" +
"text-justify: distribute;" +
"}" +
"p" +
"{" +
"font-size: 15px !important;" +
"font-family: Chap-Semibold !important;" +
"letter-spacing: 2.6px;" +
"color: white;" +
"text-align: center;" +
"}</style> \(text)"
guard let data = htmlCSSString.data(using: .utf8) else { return }
do {
let attributedStr = try NSMutableAttributedString(data: data, options: [.documentType: NSMutableAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],documentAttributes: nil)
lb_details.attributedText = attributedStr
}
I can't use NSAttributedString.Key.kern because I don't know range of text.. and can anyone please explain why only letter-spacing is not working?