Normal UILabel Is used in the application interface displays a simple text tips,but,We can also use it to display the contents of a large segment of users that do not require the participation of editors - such as reading the tweet
These contents are characterized by a need to support rich text。 UILabel of attributedText This can be done,But how we support our most common HTML markup language?
Suppose we get an HTML document,It has put the content inside it read into memory,Swift became a save in the String ,Then,You can do:
1 2 3 4 5 |
myLabel.attributedText = try? NSAttributedString(data: myHTMLString.data(using: .utf8)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:NSNumber(value: String.Encoding.utf8.rawValue) ], documentAttributes:nil) |
then,HTML frames transferred by markdown,your UILabel It can easily md text support it!
Original article written by LogStudio:R0uter's Blog » UILabel HTML rich text support
Reproduced Please keep the source and description link:https://www.logcg.com/archives/2700.html