这是代码片段:
TextField("Email", text: self.$email)
.padding()
.overlay(RoundedRectangle(cornerRadius: 1)
.stroke(Color.black, lineWidth: 1))
SecureField("Password", text: self.$password)
.padding()
.overlay(RoundedRectangle(cornerRadius: 1)
.stroke(Color.black, lineWidth: 1))
Button(action: {
print("The button was clicked!")
if loginAndPasswordAreOK() {
print("Login & Password are OK!")
} else {
self.email = ""
self.password = ""
}
}, label: {
Text("Log In")
.fontWeight(.bold)
.padding()
如果登录名和密码输入不正确,如何将电子邮件文本字段边框颜色更改为红色?
您可以为此使用显式状态变量,例如
@State private var isValid = true
...
TextField("Email", text: self.$email)
.padding()
.overlay(RoundedRectangle(cornerRadius: 1)
.stroke(isValid ? Color.black : Color.red, lineWidth: 1))
...
Button(action: {
print("The button was clicked!")
isValid = loginAndPasswordAreOK()
if isValid {
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)