I have trouble with modifying my UIView height at launch.
I have to UIView and I want one to be screen size * 70 and the other to fill the gap.
here is what I have
@IBOutlet weak var questionFrame: UIView!
@IBOutlet weak var answerFrame: UIView!
let screenSize:CGRect = UIScreen.mainScreen().bounds
and
questionFrame.frame.size.height = screenSize.height * 0.70
answerFrame.frame.size.height = screenSize.height * 0.30
It has no effect on the app during run time. I use autolayout but I only have margins constraints...
Am I doing it all wrong?
Hi create this extends if you want. Update 2015 Swift 2.0
Create File Extends.Swift and add this code (add import foundation where you want change height)
For Use (inherits Of UIView)
Swift 3 and Swift 4:
You can do this in Interface Builder:
1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select "Equal heights".
2)Then go to size inspector of the frame, click edit "Equal height to Superview" constraint, set the multiplier to 0.7 and hit return.
You'll see that constraint has changed from "Equal height to..." to "Proportional height to...".
Here you go. this should work.
This can be achieved in various methods in Swift 3.0 Worked on Latest version Jan- 2019
Directly assign the Height & Width values for a view:
Assign the CGRect for the Frame
Method Details:
Using an Extension method for CGRECT
Add following extension code in any swift file,
Use the following code anywhere in your application for the view to set the size parameters