Created
April 2, 2023 12:53
-
-
Save xremix/c6a4e476649d226bf46c3b63f62befd4 to your computer and use it in GitHub Desktop.
Alerts in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var presentAlert = false | |
@State private var username: String = "" | |
@State private var password: String = "" | |
var body: some View { | |
Button("Show Alert") { | |
presentAlert = true | |
} | |
.alert("Login", isPresented: $presentAlert, actions: { | |
TextField("Username", text: $username) | |
SecureField("Password", text: $password) | |
Button("Login", action: {}) | |
Button("Cancel", role: .cancel, action: {}) | |
}, message: { | |
Text("Please enter your username and password.") | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment