在swift中将NSAttributedString转换为html,反之亦然?

时间:2018-04-13 09:33:40

标签: html swift string nsattributedstring nsmutableattributedstring

我问,因为假答案有很多类似的问题。我接受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))

至少双重转换的结果有更大的字体。

0 个答案:

没有答案