Suppose I have three labels that are laid out below each other in a column. The uppermost label's top edge is pinned to the superview's top edge. All following labels' top edges are pinned to the preceding label's bottom edge. The leading and trailing edges of all labels are pinned to the leading and trailing edge of the superview. Here's what it looks like in Interface Builder (I added a blue background on every label to visualize its extent).

[![Screenshot showing labels in interface builder](https://i.stack.imgur.com/aMPoX.png)](https://i.stack.imgur.com/aMPoX.png)

In the simulator the result looks like this.

[![Simulator screenshot showing three labels](https://i.stack.imgur.com/SAsar.png)](https://i.stack.imgur.com/SAsar.png)

All labels are connected to outlets in a view controller.

```
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label3: UILabel!

```

When I set the text of `label2` to `nil`

```
label2.text = nil

```

the label itself collapses.

[![Simulator screenshot showing the collapsed middle label](https://i.stack.imgur.com/GZO8o.png)](https://i.stack.imgur.com/GZO8o.png)

However, the top and bottom spaces around the label do not collapse. This is evident by the fact that there is no blue background on the middle label in the last screenshot. As a result, the space between `label1` and `label3` is double the space of the layout in the first screenshot.

My question is - **on iOS8** - what is the easiest way to collapse either the middle label's top or bottom space so that the two remaining labels still use the vertical spacing defined in the original layout? To be clear, this is the result I want to achieve.

[![Simulator screenshot showing reduced spacing between the two remaining labels](https://i.stack.imgur.com/aYYVx.png)](https://i.stack.imgur.com/aYYVx.png)

Options I've found so far:

Bottom/Top Spacing Constraint Outlet
------------------------------------

Define an outlet for the middle label's top or bottom spacing constraint.

```
@IBOutlet weak var spacingConstraint: NSLayoutConstraint!

```

Store the constraint's initial constant into a variable (e.g. in `awakeFromNib` or `viewDidLoad`).

```
private var initialSpacing: CGFloat!

override func viewDidLoad() {
    initialSpacing = spacingConstraint.constant
    ...

```

Set the constraint's constant to zero whenever the text is set to `nil` or back to its initial value when the text is not `nil`.

```
spacingConstraint.constant = label2.text == nil ? 0 : initialSpacing

```

This approach feels a bit clumsy since it requires two additional variables.

Height Constraint Outlet
------------------------

Set the vertical spacing around the middle label to zero and increase its height by the same amount. Define an outlet for the height constraint and proceed as above, setting the height to zero when the text is `nil` and back to it's initial value when the height is not `nil`.

This is still as clumsy as the previous approach. In addition, you have to hardcode the spacing and cannot use the built-in default spacings (blank fields in Interface builder).

UIStackView
-----------

This is not an option since `UIStackView` is only available on iOS 9 and above.