简体   繁体   中英

How can I change the "Return" button of a textField keyboard to the blue "Done" button in SwiftUI?

I have this textField:

TextField("Username", text: $username).textFieldStyle(PlainTextFieldStyle())

How can I change its keyboard return button to the Done button?

iOS 15

You can change the return key for each textField with a simple modifier called: submitLabel that takes the return key type:

在此处输入图像描述

Image from WWDC21

Also, as you can see, you can have a callback to handle the return key press action just like the old textFieldShouldReturn function that is accessible by .onSubmit modifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM