Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct LoginView: View {
  4. @State var username: String = ""
  5. @State var password: String = ""
  6.  
  7. @State var loggedIn = false
  8.  
  9. @State var loginMessage: String = ""
  10.  
  11. func logMeIn() {
  12. self.loggedIn.toggle()
  13.  
  14. self.loginMessage = "Hello \(self.username)"
  15.  
  16. }
  17.  
  18. var body: some View {
  19. Form {
  20. TextField("Username", text: $username)
  21. .textFieldStyle(RoundedBorderTextFieldStyle())
  22. .padding()
  23.  
  24. TextField("Password", text: $password)
  25. .textFieldStyle(RoundedBorderTextFieldStyle())
  26. .padding()
  27.  
  28. HStack { if !loggedIn {
  29. if self.username.count > 0 {
  30. Button( action:logMeIn){
  31. Text("Login")
  32. }
  33. }
  34. } else {
  35. Text(loginMessage)
  36. } }
  37. }
  38. }
  39. }
  40.  
  41. #if DEBUG
  42. struct LoginView_Previews: PreviewProvider {
  43. static var previews: some View {
  44.  
  45. LoginView()
  46.  
  47. }
  48. }
  49. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement