是否可以更改“返回"?“完成"的关键在键盘上使用 SwiftUI? [英] Is it possible to change "return" key to "done" on keyboard with SwiftUI?
问题描述
在 SwiftUI 中为 TextField 打开键盘时,我没有找到任何将返回"键更改为完成"的链接或指南.
I didn't find any link or guide to change the "return" key to "done" when keyboard open for TextField in SwiftUI.
现在可以不自定义 UITextField 吗?
Is it possible now without customising UITextField?
推荐答案
iOS 15
您可以使用一个简单的修饰符更改每个 textField
的返回键:submitLabel
,它采用返回键类型:
iOS 15
You can change the return key for each textField
with a simple modifier called: submitLabel
that takes the return key type:
图片来自 WWDC21
此外,如您所见,您可以使用回调来处理返回键按下操作,就像可以通过 .onSubmit
修饰符访问的旧 textFieldShouldReturn
函数一样.
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.
⚠️ 似乎 Xcode 13 beta 1 上有一个错误,阻止此修饰符在某些情况下工作.
这篇关于是否可以更改“返回"?“完成"的关键在键盘上使用 SwiftUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!