Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a view with a half of screen height?

I want to set view1's height to half of the screen's height for all devices (when the device in the portrait mode)

Here is what I want it to look like:

enter image description here

so I make an auto layout of View1's height

    @IBOutlet weak var heighConstraint: NSLayoutConstraint!

my viewwillappear function here:

override func viewWillAppear(animated: Bool) {
        self. heighConstraint.constant = self.view.frame.size.height / 2
}

But it's not worked when I ran my app. what's wrong in here?

like image 790
Hieu Duc Pham Avatar asked May 26 '15 11:05

Hieu Duc Pham


1 Answers

I know the accepted answer is correct but there is simpler method to do so -

Add the view (the one shown in yellow color). Pin it to three edges (top, leading and trailing). I have set it as 0 but change it as per your need.

enter image description here

Create Height Equal to constraint to main View as

enter image description here

enter image description here

Open that Constraint in the Inspector view and edit the multiplier as 0.5. Setting it as 0.5 takes the height value of half the height of mainView.

enter image description here

Just make sure FirstItem = View1 and SecondItem = SuperView as shown in the image.

like image 168
Jen Jose Avatar answered Oct 20 '22 06:10

Jen Jose