Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 12, 2020 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/a144d6c6a8cb31c1f6356fc66060e818 to your computer and use it in GitHub Desktop.
Save stevencurtis/a144d6c6a8cb31c1f6356fc66060e818 to your computer and use it in GitHub Desktop.
fullVC
class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .blue
print (self.view.bounds)
let subView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
subView.backgroundColor = .black
self.view.addSubview(subView)
subView.translatesAutoresizingMaskIntoConstraints = false
subView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 100).isActive = true
subView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -100).isActive = true
subView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100).isActive = true
subView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -100).isActive = true
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print ("will")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print ("did")
}
override func viewDidDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
}
override func viewDidLayoutSubviews() {
super.viewWillLayoutSubviews()
button.frame = CGRect(x: (self.view.frame.width / 2) - (self.button.frame.width / 2), y: self.view.frame.height - 100, width: button.frame.width, height: button.frame.height )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment