How to resize a view using Xcode auto-layout

This is the first time I am using the Xcode auto-link feature in a project where I have several NSPopUpButtons. Now what I want to achieve is to have two popUpButtons in a row along with my labels, and when the window is resized, I want both popUpButtons to change their width, keeping the horizontal distance between them.

However, no matter how I apply the constraints, I just don't get popUpButtons to resize them using the window. They will always violate their horizontal restrictions and simply increase / decrease the distance to the marks. I hope it will be a little clearer what I did with this screenshot:

enter image description here

I set the spacing between labels and popUpButtons to fixed values ​​with a priority of 1000 and set width limits for popUpButtons to be greater than or equal to the initial size.

How do I set my popUpButtons resizing limits?

+6
source share
1 answer

When writing this question, I realized what the trick is:

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

enter image description here

Obviously, this controls how closely the gaze wants to “hug” its contents. Therefore, when the crawl priority is higher than the resize priority, the view does not want to increase its size because it would mean to have a more empty space between its borders and its contents.

Then, in my special case, I could also snap both NSPopUpButton buttons to the same width and voilà: popUpButtons would perfectly resize while keeping the spacing constant.

+13
source

Source: https://habr.com/ru/post/923661/


All Articles