Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equal widths / heights with parent (root) view?

Tags:

ios

autolayout

I'm trying to add constraint in Storyboard to an UIImageView to it's superview, equal widths or heights but it's disabled.

I tried selecting both the view and the superview, then the add constraints button at the bottom right (mentioned constraints appear disabled), I tried dragging from view to the superview (mentioned constraints aren't listed).

I tried removing all the constrants related to my view. Didn't make a difference.

I'm using a xib, of a custom view. The parent view is also the root view. XCode 6.2 beta. Using size class Any/Any.

Any idea? Thanks.

like image 609
User Avatar asked Jun 08 '26 23:06

User


1 Answers

For making UIView height/Width equals to super View.
Here's what you need to do.

You can set leading,top,tailing and bottom constraint by right clicking to View and select superview. enter image description here After setting Top and bottom constraints as i've set in previous image. You need to update constraints to '0' as it might have top and leading space not equal to '0'. You can select those constraints and changes constant to '0'. enter image description here You can also set constraints from pin to View as i've set for leading and tailing you can also set top and bottom option in similar way. enter image description here

EDIT:
If you want to set width and height equally then you need to select both the view and set it's equal height and equal width. As I've set them in below image. enter image description here enter image description here enter image description here

Result:
enter image description here Below two images shows how you can changes width/ height using multiplier as you need to set constant to 0.9. as from storyboard or xib you cannot set constant in float. So you need to set multiplier.
First Image I've set multiplier in ratio. enter image description here
Second Image I've set multiplier to 0.9 enter image description here

If you still face any queries please let me know. Hope this will help you solve your problem.

like image 170
Dhaivat Vyas Avatar answered Jun 10 '26 14:06

Dhaivat Vyas