Swift: How to display text with HTML tags using attributed text and adjust its font to system font

Was ist <u>keine</u> Leitlinie von CHECK24?
plain text displayed in a UILabel
let yourText = "Was ist <u>keine</u> Leitlinie von CHECK24?"
let data = Data(yourText.utf8)
if let attributedString = try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) {
yourUILabel.attributedText = attributedString
let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
yourUILabel.font = font
[.documentType: NSAttributedString.DocumentType.html]
let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
attributed text displayed in a UILabel



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic