Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Last active February 28, 2016 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertmryan/8af2c98902e39a60e177 to your computer and use it in GitHub Desktop.
Save robertmryan/8af2c98902e39a60e177 to your computer and use it in GitHub Desktop.
Resize views in `viewWillLayoutSubviews`
class ViewController: UIViewController {
var redView: UIView!
var greenView: UIView!
var blueView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
redView = UIView()
redView.backgroundColor = UIColor.redColor()
view.addSubview(redView)
blueView = UIView()
blueView.backgroundColor = UIColor.blueColor()
view.addSubview(blueView)
greenView = UIView()
greenView.backgroundColor = UIColor.greenColor()
view.addSubview(greenView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
redView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height / 3.0)
greenView.frame = CGRect(x: 0, y: view.frame.size.height * 1.0 / 3.0, width: view.frame.size.width, height: view.frame.size.height / 3.0)
blueView.frame = CGRect(x: 0, y: view.frame.size.height * 2.0 / 3.0, width: view.frame.size.width, height: view.frame.size.height / 3.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment