smoothumut
smoothumut

Reputation: 3491

proportional height of view and superview autolayout

I have a small view that I want him occupy 1/3 height of superview(same size with safe area)

I defined leading space, trailing space, bottom space which its constant = 0 with superview.bottom.

AND I want to make the height 1/3 of superview height to make it same look in all iphone sizes. I defined aspect ratio and changed its first item as superview.height and second item as thisview.height. of course I have defined 3:1 multiplier enter image description here enter image description here

But it doesnt work it gives following error

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal.

Come on!! why doesnt it work? this is not that complex compared to all other stuff. Also how can I complish this on interface. (not in code) I would like to see it on xcode with all other screensizes in preview tab.

Thanks a lot for your time.

Upvotes: 2

Views: 3736

Answers (1)

Ricky Mo
Ricky Mo

Reputation: 7648

Set the view Equal Heights with its superview. Then change the multiplier of the Equal Heights constraint to 1:3

enter image description here

Upvotes: 10

Related Questions