Mike Lischke
Mike Lischke

Reputation: 53337

Auto layout alignment issue

In one of my outline views (view based) I got 2 cell views (header and content):

enter image description here

The badge button has vertical centering + trailing distance constraints to the superview. Left to it is the cash field with the same constraints (though trailing distance is relative to the badge). Left to that is the name field with leading + trailing constraints as well as vertical centering. None of the 3 has a fixed width, so they all resize dynamically (the rightmost 2 depending on their content). Works all fine and well.

Now the question: when there is nothing to show in the badge I hide it and would like the cash field to take the space that was formerly taken by the badge, to not let a big gap there. How to accomplish that?

If there was a width constraint I could just set this to 0 and the layouter would take care (have done this with a height in another place). But I don't have a width constraint (auto resize). So what else could I use, except handling everything manually?

Upvotes: 0

Views: 60

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90541

You can use an NSStackView to arrange the views in the row. As of 10.11, it can automatically adjust the layout to account for hidden subviews.

Upvotes: 1

Related Questions