Reading time: 2 min

This recipe shows how to use specify SwiftUI Colors with hex values, either hexadecimal numbers or strings. The end result can look like this:

preview

To make this work, you have to add two extensions to your codebase.

The first one allows you to specify a hex color from an Int, which you can conv...

Continue Reading...

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: 2 min

This quick tip shows how to speed up your SwiftUI development by simply breaking the code of your Views into smaller chunks. This results in:

  • Faster Source Editor operation, i.e syntax highlighting and error/warnings checks will come in faster.
  • Faster preview build and refresh time.
  • Fast...

Continue Reading...