How to customize the submit button for TextField, SecureField, and TextEditor
About 2 min
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)
}
}
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