Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an item full width in auto layout constraint?

I'm trying to make a button full width in ios 9 storyboards, and am trying to create a width auto constraint, but the width constraint only seems to take an exact static number. How do I make the item go full width.

Additionally if I wanted say an imageview to be full height and adjustable width to maintain it's aspect ratio - or a size to fit fill, how would I do that with the auto layout constraints in the storyboard.

Should I be doing this programmatically in the view controller?

like image 757
MonkeyBonkey Avatar asked Jan 07 '23 11:01

MonkeyBonkey


1 Answers

For the button:

In storyboard drag the left and right sides of the button to make it full width. Make sure the button is selected and add a pin constraint to the left and right (if you've dragged it full width the pin constraint should be equal to -20)

Pin Constraints

For the imageView:

The full height constraint is done almost exactly the same, although this time you need to drag the top and bottom to the top and bottom edges of the view controller and pin the top and bottom to their respective Layout guide.

You can make the image full screen in the view controller (pin top, bottom, left & right) and then edit the aspect ratio of the image in the Attributes inspector when the imageView is selected:

Attribute inspector

Hope that helps!

like image 152
Kitson Avatar answered Jan 17 '23 14:01

Kitson