Last active
February 28, 2016 23:23
-
-
Save robertmryan/8af2c98902e39a60e177 to your computer and use it in GitHub Desktop.
Resize views in `viewWillLayoutSubviews`
This file contains 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
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