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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is tokenizer, analyzer and filter in Elasticsearch ?

Improving the Security of Your Developments With These Open Source Tools

CSS Animations — Keyframes & the After Pseudo Element With Transitions Pt. I

Building a CV Builder with BIRT in KNIME — Part 1

Router Protocol: Development Update ( June 23)

How I Stopped Procrastinating and Started Working on Coding Side-Projects

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
Akarsh SEGGEMU

Akarsh SEGGEMU

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

More from Medium

How to build iOS Authentication with Firebase Part II Sign Up User 2022

Becoming a Swift Developer (Week 2)

Test Double : Stub

SwiftUI | Fetch JSON data & display it into a list