Reading time: 1 min

This recipe shows how to handle conversions between UIKit UIFont and SwiftUI Font, as there are more than a few instances where using both is necessary. This mainly comes into play when you import UIViews into SwiftUI via UIViewRepresentable.

OK, so here's how it is:

  • Converting UIFon...

Continue Reading...

Reading time: 1 min

This quick recipe show how to list and display all the fonts that are available by default in your iOS/MacOS app. The end result looks like this:

preview

Here's the code:

let allFontNames = UIFont.familyNames
  .flatMap { UIFont.fontNames(forFamilyName: $0) }

var body: some View {
  List(allFontNames...

Continue Reading...

Reading time: 1 min

This recipe shows how to render justified text in SwiftUI. The end result looks like this:

preview

Unfortunately, SwiftUI doesn't support justifying text natively. The TextAlignment enum doesn't contain this option, forcing us to resort to good old UIViewRepresentable to make it happen:

struct J...

Continue Reading...

Reading time: 3 min

This recipe shows how to display text with tappable hyperlinks in SwiftUI, and, in doing so, fully support attributed strings, HTML and Markdown in text views on any SwiftUI version. The end result looks like this:

preview

The solution depends on which SwiftUI version you have to support:

  1. SwiftU...

Continue Reading...

Reading time: 1 min

This recipe shows how to use markdown in SwiftUI Text views. The end result looks like this:

preview

This code works starting with SwiftUI 3 (iOS 15, macOS 12). If you're interested in using attributed strings on SwiftUI 1 and 2, check out Text with NSAttributedString recipe or Hyperlinks with Te...

Continue Reading...