Skip to main content

How to customize the submit button for TextField, SecureField, and TextEditor

About 2 minSwiftSwiftUIArticle(s)bloghackingwithswift.comcrashcourseswiftswiftuixcodeappstore

How to customize the submit button for TextField, SecureField, and TextEditor 관련

SwiftUI by Example

Back to Home

How to customize the submit button for TextField, SecureField, and TextEditor | SwiftUI by Example

How to customize the submit button for TextField, SecureField, and TextEditor

Updated for Xcode 15

New in iOS 15

By default, TextField and SecureField show a simple “Return” button on the keyboard, but the submitLabel() modifier let us choose from a range of alternatives.

For example, if you wanted to show the localized form of “Join” for the button, you would use this:

struct ContentView: View {
    @State private var username = ""

    var body: some View {
        TextField("Username", text: $username)
            .submitLabel(.join)
    }
}

Download this as an Xcode projectopen in new window

A keyboard with a blue “join” button in the bottom right.
A keyboard with a blue “join” button in the bottom right.

There are lots of different button options you choose from by passing different values to submitLabel():

  • continue
  • done
  • go
  • join
  • next
  • return
  • route
  • search
  • send

All those work equally well with TextField, SecureField, and TextView.

Similar solutions…
How to create secure text fields using SecureField | SwiftUI by Example

How to create secure text fields using SecureField
How to make a TextField or TextEditor have default focus | SwiftUI by Example

How to make a TextField or TextEditor have default focus
How to create multi-line editable text with TextEditor | SwiftUI by Example

How to create multi-line editable text with TextEditor
How to change the background color of List, TextEditor, and more | SwiftUI by Example

How to change the background color of List, TextEditor, and more
How to take action when the user submits a TextField | SwiftUI by Example

How to take action when the user submits a TextField

이찬희 (MarkiiimarK)
Never Stop Learning.