in the book page 254 about SecureField
“@State var password = “”
…
SecureField.init(“Password”, text: $password)
.textFieldStyle(RoundedBorderTextFieldStyle())”
why I run the iPhone8 similator ,focus on it with softkeyboard,
then the background of secure field become yellow, at righthand side of secure field show “Strong password”
if not using soft keyboard, using mac keyboard for simulator input, just show dot . which is different to what soft keyboard input.
if run in the real device if input also show dot.
any idea why it show Strong password"?
below is another post, is not my post, but it is the same look,
show Strong password, and yellow background .
the way to reproduce open 07-controls-and-user-input/final project in Register view file .
add
@State var password = “”
SecureField(“Password”, text: $password)
below is full code in registerview file. then run in simulator , got the issue.
and I found , if delete
TextField(“Type your name…”, text: $userManager.profile.name)
from below code, then securefield will behavor back to normal, using softkeyboard in the simulator, show dot.
import SwiftUI
struct RegisterView: View {
@EnvironmentObject var userManager: UserManager
@ObservedObject var keyboardHandler: KeyboardFollower
init(keyboardHandler: KeyboardFollower) {
self.keyboardHandler = keyboardHandler
}
@State var password = “”
var body: some View {
VStack {
Spacer()
WelcomeMessageView()
TextField("Type your name...", text: $userManager.profile.name)
SecureField("Password", text: $password)
HStack {
Spacer()
Text("\(userManager.profile.name.count)")
.font(.caption)
.foregroundColor(userManager.isUserNameValid() ? .green : .red)
.padding(.trailing)
}
.padding(.bottom)
HStack {
Spacer()
Toggle(isOn: $userManager.settings.rememberUser) {
Text("Remember me")
.font(.subheadline)
.foregroundColor(.gray)
}
.fixedSize()
}
Button(action: self.registerUser) {
HStack {
Image(systemName: "checkmark")
.resizable()
.frame(width: 16, height: 16, alignment: .center)
Text("OK")
.font(.body)
.bold()
}
}
.bordered()
.disabled(!userManager.isUserNameValid())
Spacer()
}
.padding(.bottom, keyboardHandler.keyboardHeight)
.edgesIgnoringSafeArea(keyboardHandler.isVisible ? .bottom : [])
.padding()
.background(WelcomeBackgroundImage())
}
}
// MARK: - Event Handlers
extension RegisterView {
func registerUser() {
if userManager.settings.rememberUser {
userManager.persistProfile()
} else {
userManager.clear()
}
userManager.persistSettings()
userManager.setRegistered()
}
}
struct RegisterView_Previews: PreviewProvider {
static let user = UserManager(name: “Ray”)
static var previews: some View {
RegisterView(keyboardHandler: KeyboardFollower())
.environmentObject(user)
}
}