Skip to content

Instantly share code, notes, and snippets.

@martinlasek
Created November 14, 2019 18:16
Show Gist options
  • Save martinlasek/d20ea6b1114a9ef7a84fad0b7700bb75 to your computer and use it in GitHub Desktop.
Save martinlasek/d20ea6b1114a9ef7a84fad0b7700bb75 to your computer and use it in GitHub Desktop.
//
// WelcomeVC.swift
// TokiTalkie-App
//
// Created by Martin Lasek on 14.11.19.
// Copyright © 2019 Martin Lasek. All rights reserved.
//
import UIKit
class WelcomeVC: UIViewController {
var safeArea: UILayoutGuide!
let titleLabel = UILabel()
let usernameTextField = UITextField()
let enterChatButton = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
safeArea = view.layoutMarginsGuide
setupNavigation()
setupTitle()
setupUsernameTextField()
setupEnterChatButton()
}
private func setupNavigation() {
navigationItem.title = "Welcome"
}
private func setupTitle() {
view.addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
let top = titleLabel.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 150)
let centerX = titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor)
NSLayoutConstraint.activate([top, centerX])
titleLabel.text = "TokiTalkie Chat"
titleLabel.font = .systemFont(ofSize: 32)
}
private func setupUsernameTextField() {
view.addSubview(usernameTextField)
usernameTextField.translatesAutoresizingMaskIntoConstraints = false
let top = usernameTextField.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 50)
let centerX = usernameTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let width = usernameTextField.widthAnchor.constraint(equalToConstant: 200)
let height = usernameTextField.heightAnchor.constraint(equalToConstant: 35)
NSLayoutConstraint.activate([top, centerX, width, height])
usernameTextField.placeholder = "Username"
usernameTextField.layer.borderWidth = 1
usernameTextField.layer.borderColor = UIColor.black.cgColor
usernameTextField.layer.cornerRadius = 4
usernameTextField.textAlignment = .center
}
private func setupEnterChatButton() {
view.addSubview(enterChatButton)
enterChatButton.translatesAutoresizingMaskIntoConstraints = false
let top = enterChatButton.topAnchor.constraint(equalTo: usernameTextField.bottomAnchor, constant: 25)
let centerX = enterChatButton.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let width = enterChatButton.widthAnchor.constraint(equalToConstant: 200)
let height = enterChatButton.heightAnchor.constraint(equalToConstant: 35)
NSLayoutConstraint.activate([top, centerX, width, height])
enterChatButton.backgroundColor = .black
enterChatButton.layer.cornerRadius = 4
enterChatButton.setTitle("Enter", for: .normal)
enterChatButton.setTitleColor(.lightGray, for: .highlighted)
//enterChatButton.addTarget(self, action: #selector(enterChatRoomAction), for: .touchUpInside)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment