How do I customize a half-height view?
I want to set the height of view1 to half the height of the screen for all devices (when the device is in portrait mode)
Here's what I want it to look like:
so i am doing auto height layout of View1
@IBOutlet weak var heighConstraint: NSLayoutConstraint!
my viewwillappear here:
override func viewWillAppear(animated: Bool) {
self. heighConstraint.constant = self.view.frame.size.height / 2
}
But it didn't work when I started the application. what is wrong here?
source to share
I know the accepted answer is correct, but there is an easier way to do it -
Add a view (the one shown in yellow). Connect it to the three edges (top, front and back). I set it to 0, but changed it to suit your needs.
Create a height equal to the constraint on main. Kind as
Open this constraint in Inspector view and edit the multiplier as 0.5. By setting it to 0.5, the height value will be half the height of the mainView.
Just make sure FirstItem = View1 and SecondItem = SuperView as shown in the image.
source to share