How to move the search widget to the bottom of the iOS app

Asked on 07/31/2024

1 search

To move the search widget to the bottom of your iOS app, you can use the new control placement API introduced in iOS 18. This API allows you to specify the placement of controls, including the search widget, in various positions such as leading, trailing, and bottom.

Here's a brief overview of how you can achieve this:

  1. Use the Control Placement API: The API provides a way to place controls at different positions on the screen. For moving the search widget to the bottom, you would use the bottom placement.

  2. Implementing the Placement: You can specify the placement in your SwiftUI code. For example, if you are using a SearchBar, you can set its placement to bottom.

Here is a simple example in SwiftUI:

struct ContentView: View {
    var body: some View {
        VStack {
            Spacer()
            SearchBar()
                .controlPlacement(.bottom)
        }
    }
}

This code places the SearchBar at the bottom of the view.

For more detailed information, you can refer to the session What’s new in StoreKit and In-App Purchase where the control placement API is discussed.

Relevant Sessions

These sessions provide insights into the new APIs and how to use them effectively in your apps.