I am using a combination of TextField and SecureField on my Login screen of the app, user can click the eye button to show and hide text using this code:
ZStack(alignment: .trailing){
if isSecured{
SecureField(placeholder, text: $text)
.padding(.trailing, 35)
}else{
TextField(placeholder, text: $text)
.padding(.trailing, 35)
}
Button {
isSecured = !isSecured
} label: {
Image(systemName: isSecured ? "eye.slash" : "eye")
}
}
.background(
Color.gray
.frame(height: 0.5)
.padding(.top, 40)
)
So, when the user clicks the eye button to show the password and then again clicks the eye button after it to hide the password leads SecureField to auto-clear password on entering text, is there any way that password doesn't auto-clear? thanks