Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a view resize using Xcode's auto layout

I am using Xcode's auto layout feature for the first time in a project where I have several NSPopUpButtons. Now what I want to achieve is to have two popUpButtons in a row together with their labels and when the window is resized I want both popUpButtons to adjust their width while keeping the horizontal spacing between each other.

However no matter how I apply the constraints I just don't get the popUpButtons to change their size with the window. They will always break their horizontal spacing constraints and just increase/decrease the spacing to the labels. I hope it gets a bit clearer what I have done from this screenshot:

enter image description here

I have set the spacings between the labels and the popUpButtons to fixed values with 1000 priority and have set the width constraints fo the popUpButtons to be greater or equal to the initial size.

How must I set my constraints to have the popUpButtons resize?

like image 650
codingFriend1 Avatar asked Aug 24 '12 12:08

codingFriend1


1 Answers

While writing this question I realized what the trick is:

In the size inspector of the NSPopUpButton I had to reduce the Content Hugging Priority.

enter image description here

Obviously this controls how closely the view wants to 'hug' its content. So when the hugging priority is higher than the resize priority the view will not want to increase its size because that would mean to have more empty space between its bounds and its content.

Then in my special case, I could also pin both NSPopUpButtons to have the same width and voilà: the popUpButtons will perfectly resize while keeping the spacing constant.

like image 91
codingFriend1 Avatar answered Oct 19 '22 04:10

codingFriend1