Create an App with Login Page iOS swift
import UIKit
class LoginViewController: UIViewController {
let usernameTextField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.placeholder = "Username"
textField.borderStyle = .roundedRect
return textField
}()
let passwordTextField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.placeholder = "Password"
textField.borderStyle = .roundedRect
textField.isSecureTextEntry = true
return textField
}()
let loginButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Login", for: .normal)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(usernameTextField)
view.addSubview(passwordTextField)
view.addSubview(loginButton)
NSLayoutConstraint.activate([
usernameTextField.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 40),
usernameTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
usernameTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
passwordTextField.topAnchor.constraint(equalTo: usernameTextField.bottomAnchor, constant: 20),
passwordTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
passwordTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
loginButton.topAnchor.constraint(equalTo: passwordTextField.bottomAnchor, constant: 40),
loginButton.centerXAnchor.constraint(equalTo: view.centerXAnchor)
])
}
}
Comments
Post a Comment