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...

Reading time: 8 min

This recipe shows how to format content of a SwiftUI Text with HTML via NSAttributedString on any SwiftUI version. The end result looks like this:

Screenshot%202021-05-26%20at%2014.24.29

There are two solutions in this recipe:

  1. SwiftUI 3 (iOS 15, macOS 12) brings in a new AttributedString wrapper around NSAttributedString...

Continue Reading...

Reading time: 2 min

This recipe shows how to add a TextField to a SwiftUI alert dialog. The end result looks like this:

The dialog supports:

  1. Custom title and message.
  2. Text field with a placeholder and keyboard type.
  3. Confirm button, whose callback returns the content of the text field.
  4. Optiona...

Continue Reading...

Reading time: 1 min

Ocassionally you wish to make a View fit entire width of its parent. You can do so by setting both minWidth and maxWidth:

Text("Some text")
  .frame(minWidth: 0, maxWidth: .infinity)

For a Text specifically, this is even more useful if you wish to have it, say, leading-aligned in a center-...

Continue Reading...