使用 Swift5.1.2, iOS13.2, Xcode-11.2,
在 Stackview 中有几个 TextField,我想在用户在第一个 TextField 中键入 x 数量的字符后立即移动到下一个 TextField。
通过此链接,我可以识别 TextField 条目何时达到 x 字符数。但是,我不知道如何让 firstResponder 跳转到我的 StackView 中的第二个 TextField。
SwiftUI 有解决方案吗?
我在 SwiftUI 中构建了一个登录屏幕。SecureField
当用户完成输入他们的电子邮件时,我想专注于密码。我怎样才能做到这一点?
struct LoginView: View {
@State var username: String = ""
@State var password: String = ""
var body: some View {
ScrollView {
VStack {
TextField("Email", text: $username)
.padding()
.frame(width: 300)
.background(Color(UIColor.systemGray5))
.cornerRadius(5.0)
.padding(.bottom, 20)
.keyboardType(.emailAddress)
SecureField("Password", text: $password)
.padding()
.frame(width: 300)
.background(Color(UIColor.systemGray5))
.cornerRadius(5.0)
.padding(.bottom, 20)
Button(action: {
}, label: {
Text("Login")
.padding()
.frame(width: 300)
.background((username.isEmpty || password.isEmpty) ? Color.gray : Color(UIColor.cricHQOrangeColor()))
.foregroundColor(.white)
.cornerRadius(5.0)
.padding(.bottom, 20)
}).disabled(username.isEmpty || password.isEmpty)
Run Code Online (Sandbox Code Playgroud) 在 SwiftUI 中为 TextField 打开键盘时,我没有找到任何将“返回”键更改为“完成”的链接或指南。
现在可以不自定义 UITextField 吗?