Reading time: 1 min

This recipe shows how to navigate from one text field to another using keyboard buttons in SwiftUI by combining @FocusState and onSubmit. The end result looks like this:

preview

The recipe goes as following:

  1. Declare an enum that holds aliases for focusable fields. In the code below, that's Form...

Continue Reading...

Reading time: 1 min

This recipe shows how to add a toolbar with action buttons on the top of soft keyboard in SwiftUI. The end result looks like this:

Simulator%20Screen%20Shot%20-%20iPhone%20SE%20%282nd%20generation%29%20-%202021-08-19%20at%2020.31.05

This feature is available starting with SwiftUI 3 (iOS 15, macOS 12).

The pattern for adding the toolbar to the keyboard is the same as with toolbar setups,...

Continue Reading...

Reading time: 1 min

Here's a quick recipe for getting the key window, top or root View Controller, in a scene-based SwiftUI app:

extension UIApplication {
  var currentKeyWindow: UIWindow? {
    UIApplication.shared.connectedScenes
      .filter { $0.activationState == .foregroundActive }
      .map { $0 as? UIWind...

Continue Reading...

Reading time: 1 min

A common issue in SwiftUI is that, when the keyboard appears, it covers up a part of your UI. This is especially problematic if it overlaps the exact TextField you're editing, so that you can't even see what you're typing!

Take this credit card input field at the bottom of a screen:

If you o...

Continue Reading...