Search code examples
iosobjective-cautolayout

hide a view and remove blank spaces


I'm developing an app for iOS and I'm using the Storyboard with AutoLayout ON. One of my view controllers has a set of 3 labels, and in certain circumstances i would like to make the second one disappear.

If I use the setHidden:TRUE method the label become invisible but it still obviously take space in the view.

can someone point me to the right direction?


Solution

  • The simplest solution is to put the views that you want to hide inside a StackView. Then to hide the element simply make it hidden:

    _myElement.hidden = YES;
    

    StackView will squash hidden elements and they will become invisible.