Guest User

Untitled

a guest
Dec 4th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import UIKit
  2. import Cartography
  3.  
  4. class ViewCodeLoginViewController: LoginViewController {
  5.  
  6. let userTextField: UITextField = {
  7. let text = UITextField()
  8. text.placeholder = "username"
  9. text.textColor = .black
  10. return text
  11. }()
  12.  
  13. let passTextField: UITextField = {
  14. let text = UITextField()
  15. text.placeholder = "password"
  16. text.textColor = .black
  17. return text
  18. }()
  19.  
  20. lazy var loginButton: UIButton = { [weak self] in
  21. let button = UIButton()
  22. button.setTitle("login", for: .normal)
  23. button.addTarget(self, action: #selector(login), for: .touchUpInside)
  24. button.setTitleColor(.black, for: .normal)
  25. return button
  26. }()
  27.  
  28. override func loadView() {
  29. let view = UIView()
  30.  
  31. view.addSubview(userTextField)
  32. view.addSubview(passTextField)
  33. view.addSubview(loginButton)
  34.  
  35. self.view = view
  36. }
  37.  
  38. override func viewDidLoad() {
  39.  
  40. constrain(self.view, userTextField, passTextField, loginButton) { view, user, pass, button in
  41. user.top == view.top + 50
  42. user.left == view.left + 20
  43. user.right == view.right - 20
  44.  
  45. pass.top == user.bottom + 20
  46. pass.left == user.left
  47. pass.right == user.right
  48.  
  49. button.top == pass.bottom + 20
  50. button.right == pass.right
  51. button.left == pass.left
  52. button.height == 40
  53. }
  54.  
  55. self.view.backgroundColor = .white
  56.  
  57. }
  58.  
  59. func login() {
  60.  
  61. username = userTextField.text
  62. password = passTextField.text
  63.  
  64. self.delegate?.login(username: self.username!, password: self.password!) { response in
  65. if response {
  66. print("user login viewcode")
  67. } else {
  68. print("fail to login viewcode")
  69. }
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment