Reading time: 1 min

This tutorial shows how to create a custom Swiftui Button style with distinct disabled and pressed states. The end result will look like this:

Default Pressed Disabled

Let's get down to business! First, define three colors that represent the default and disabled state. Also throw i...

Continue Reading...

Reading time: 1 min

When implementing a custom TextField by wrapping a UITextField in UIViewRepresentable (just like we did in our custom SecureField that tracks focus change, you need to be careful as its size normally grows with its content. This can lead to the field spilling outside the bounds of its parent...

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

Reading time: 2 min

Detecting if a text field gained or lost focus is not entirely straightforward in SwiftUI.

TextField constructor has a parameter named onEditingChanged, but it triggers only when the user taps the return key in the virtual keyboard, not when the focus is actually lost.

Even worse, SecureFi...

Continue Reading...