Last active
April 7, 2018 23:40
-
-
Save omaralbeik/de31dc4df53f06c46bbf658295760815 to your computer and use it in GitHub Desktop.
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
import UIKit | |
protocol LoginViewDelegate: class { | |
func loginView(_ view: LoginView, didTapLoginButton button: UIButton) | |
} | |
class LoginView: View { | |
weak var delegate: LoginViewDelegate? | |
var emailAddress: String { | |
return emailTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | |
} | |
var password: String { | |
return passwordTextField.text ?? "" | |
} | |
private lazy var emailTextField: UITextField = { | |
let textField = UITextField() | |
textField.placeholder = "Email Address" | |
textField.keyboardType = .emailAddress | |
return textField | |
}() | |
private lazy var passwordTextField: UITextField = { | |
let textField = UITextField() | |
textField.placeholder = "Password" | |
textField.isSecureTextEntry = true | |
return textField | |
}() | |
private lazy var loginButton: UIButton = { | |
let button = UIButton(type: .system) | |
button.setTitle("Login", for: .normal) | |
return button | |
}() | |
override func setViews() { | |
super.setViews() | |
addSubview(emailTextField) | |
addSubview(passwordTextField) | |
addSubview(loginButton) | |
loginButton.addTarget(self, action: #selector(didTapLoginButton(_:)), for: .touchUpInside) | |
} | |
override func layoutViews() { | |
// layout your subviews here, consider using SnapKit, it is amazing! | |
} | |
} | |
// MARK: - Actions | |
private extension LoginView { | |
@objc func didTapLoginButton(_ button: UIButton) { | |
delegate?.loginView(self, didTapLoginButton: button) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment