UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Is there a way to easily display rich text in SwiftUI?

Forums > SwiftUI

I am displaying a multiline text in a Text component. Ideally, I'd prefer some lines to be shown bold, like they are headers. I made a search and only found advice which was rather old. So far, I will probably go the RichText custom component way (https://github.com/NuPlay/RichText).

However, displaying rich text is such a basic thing, and it existed in UIKit. So I am thinking maybe in the most up-to-date version of SwiftUI this was already made possible, and I simply was unable to find that?

2      

You may want to look at the inline text markdown options that were introduced in iOS15.

WWDC21 Video

See if it will be enough for you.

3      

Thank you, it was a useful pointer. From those videos I understood that Markdown support does exist. But the answer how to enable it I found here: https://www.hackingwithswift.com/quick-start/swiftui/how-to-render-markdown-content-in-text

2      

Alex seeks to use Markdown, but missed an opportunity in his last post!

Adding URLs to Forum Posts


You can add Markdown links to your Hacking With Swift forum posts! This allows you to hide the full URL, and provide an easy-to-read description.

Whilst composing your response, place the link's description inside a pair of square brackets:

// The description is inside the square brackets...
See -> [Enable Markdown in XCode]

Immediately after the square brackets, embed the URL inside of parenthesis:

// The URL is inside the parenthesis right after the description...
See -> [Enable Markdown in XCode](https://www.hackingwithswift.com/quick-start/swiftui/how-to-render-markdown-content-in-text)

When rendered in Markdown, you see the description, but the URL is hidden.
You get a simple, cleaner link for your readers.
Like this....

See -> Enable Markdown in XCode

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.