Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct LoginView: View {
- @State var username: String = ""
- @State var password: String = ""
- @State var loggedIn = false
- @State var loginMessage: String = ""
- func logMeIn() {
- self.loggedIn.toggle()
- self.loginMessage = "Hello \(self.username)"
- }
- var body: some View {
- Form {
- TextField("Username", text: $username)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- TextField("Password", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- HStack { if !loggedIn {
- if self.username.count > 0 {
- Button( action:logMeIn){
- Text("Login")
- }
- }
- } else {
- Text(loginMessage)
- } }
- }
- }
- }
- #if DEBUG
- struct LoginView_Previews: PreviewProvider {
- static var previews: some View {
- LoginView()
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement