Created
September 22, 2017 22:49
-
-
Save farhan-syed/ed39999f14ed4adc37c6cdb4bc354998 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class View: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
addViews() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
let emailTextField: UITextField = { | |
let textField = UITextField() | |
textField.placeholder = "email" | |
textField.borderStyle = .roundedRect | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
return textField | |
}() | |
let firstNameTextField: UITextField = { | |
let textField = UITextField() | |
textField.placeholder = "first name" | |
textField.borderStyle = .roundedRect | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
return textField | |
}() | |
let lastNameTextField: UITextField = { | |
let textField = UITextField() | |
textField.placeholder = "last name" | |
textField.borderStyle = .roundedRect | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
return textField | |
}() | |
lazy var saveButton: UIButton = { | |
let button = UIButton(type: UIButtonType.system) | |
button.setTitle("Save", for: .normal) | |
button.setTitleColor(.black, for: .normal) | |
button.translatesAutoresizingMaskIntoConstraints = false | |
// button.addTarget(self, action: #selector(saveButtonTapped(_:)), for: .touchUpInside) | |
return button | |
}() | |
func addViews(){ | |
addSubview(emailTextField) | |
addSubview(firstNameTextField) | |
addSubview(lastNameTextField) | |
addSubview(saveButton) | |
emailTextField.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, constant: 10).isActive = true | |
emailTextField.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true | |
emailTextField.rightAnchor.constraint(equalTo: rightAnchor, constant: -10).isActive = true | |
emailTextField.heightAnchor.constraint(equalToConstant: 35).isActive = true | |
firstNameTextField.topAnchor.constraint(equalTo: emailTextField.bottomAnchor, constant: 10).isActive = true | |
firstNameTextField.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true | |
firstNameTextField.rightAnchor.constraint(equalTo: rightAnchor, constant: -10).isActive = true | |
firstNameTextField.heightAnchor.constraint(equalToConstant: 35).isActive = true | |
lastNameTextField.topAnchor.constraint(equalTo: firstNameTextField.bottomAnchor, constant: 10).isActive = true | |
lastNameTextField.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true | |
lastNameTextField.rightAnchor.constraint(equalTo: rightAnchor, constant: -10).isActive = true | |
// lastNameTextField.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -10).isActive = true | |
lastNameTextField.heightAnchor.constraint(equalToConstant: 35).isActive = true | |
saveButton.topAnchor.constraint(equalTo: lastNameTextField.bottomAnchor, constant: 10).isActive = true | |
saveButton.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true | |
saveButton.rightAnchor.constraint(equalTo: rightAnchor, constant: -10).isActive = true | |
saveButton.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, constant: -10).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment