Спрашиваю, потому что много похожих вопросов с фейковыми ответами. Я беру свой NSAttributedString
и конвертирую в html, потом обратно в NSAttributedString
- внешний вид строки меняется. Моя строка:
let attributedString = NSMutableAttributedString(string: "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. ", attributes: [
NSFontAttributeName: UIFont.systemFont(ofSize: 13.0, weight: UIFontWeightRegular),
NSForegroundColorAttributeName: UIColor(white: 205.0 / 255.0, alpha: 1.0)
])
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 74.0 / 255.0, green: 144.0 / 255.0, blue: 226.0 / 255.0, alpha: 1.0), range: NSRange(location: 498, length: 63))
По крайней мере, результат двойного преобразования имеет более крупный шрифт.
NSAttributedString
скорее чем HTML. - person Grimxn   schedule 13.04.2018