Skip to content

Instantly share code, notes, and snippets.

@omaralbeik
Last active April 7, 2018 23:41
Show Gist options
  • Save omaralbeik/95100ca7a2f5f9aff00b259a43d0dace to your computer and use it in GitHub Desktop.
Save omaralbeik/95100ca7a2f5f9aff00b259a43d0dace to your computer and use it in GitHub Desktop.
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 = {
return UITextField(placeholder: "Email Address", keyboardType: .emailAddress)
}()
private lazy var passwordTextField: UITextField = {
return UITextField(placeholder: "Password", isSecureTextEntry: true)
}()
private lazy var loginButton: UIButton = {
return UIButton(title: "Login", image: nil)
}()
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!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment