How to create secure text fields using SecureField
About 2 min
How to create secure text fields using SecureField êŽë š
SwiftUI by Example
Back to Home
How to create secure text fields using SecureField | SwiftUI by Example
How to create secure text fields using SecureField
Updated for Xcode 15
SwiftUI's SecureField
works almost identically to a regular TextField
except the characters are masked out for privacy. Just like TextField
, you get to provide a placeholder giving the user a suggestion for what to enter, and the underlying value you bind to is still a plain string so you can check it as needed.
Here's an example that creates a SecureField
bound to a local @State
property so we can show what they typed:
struct ContentView: View {
@State private var password: String = ""
var body: some View {
VStack {
SecureField("Enter a password", text: $password)
Text("You entered: \(password)")
}
}
}
Similar solutionsâŠ
How to customize the submit button for TextField, SecureField, and TextEditor | SwiftUI by Example
How to customize the submit button for TextField, SecureField, and TextEditor
How to format text inside text views | SwiftUI by Example
How to format text inside text views
How to create static labels with a Text view | SwiftUI by Example
How to create static labels with a Text view
How to take action when the user submits a TextField | SwiftUI by Example
How to take action when the user submits a TextField
How to create multi-line editable text with TextEditor | SwiftUI by Example
How to create multi-line editable text with TextEditor