Sven Bauer
Sven Bauer

Reputation: 1689

Allign UIViews differnt when some UIViews are hidden?

I have the following view layouted with autolayout.

--------


 +


--------

The plus icon is centered vertically on the cell. This should be different when a second icon appears as you can see on the following image:

--------


 +

 X

--------

I this case both icons together should be alligined vertically centered with a space of 5 between them.

I create my constraints in code no interface builder or Storyboard.

How can I achieve this with autolayout?

Upvotes: 0

Views: 45

Answers (1)

Doro
Doro

Reputation: 2413

It's quite simple, but you need some code

  1. Create outlet for constraint, which align your '+' vertically
  2. Change 'constant' property when 'X' appears on your cell

for example

{
        if (cell.secondView.hidden == true) {
        // someConstraint - is your align constrain, which you can create throw IB
            cell.someConstraint.constant = 0;
        }
        else
        {
          // note 'minus' - to move first view up
             cell.someConstraint.constant = -cell.secondView.frame.height
        }
}

Upvotes: 1

Related Questions