how to set visibility GONE like android in IOS?

Siddharth Shah picture Siddharth Shah · May 20, 2016 · Viewed 8.3k times · Source

Anybody know a simple way to hide a label and let the other views of the screen use the place left blank ? And make the opposite when showing back that view. Something like Android setVisibility = GONE for layers.

As far as I know, using setHidden=true only hide the view from the screen but does not rearrange anything around it.

Thank you

Answer

Fonix picture Fonix · May 20, 2016

The only way to achieve Androids .GONE functionality on iOS is to use a UIStackView

via Apples documentation

Dynamically Changing the Stack View’s Content The stack view automatically updates its layout whenever views are added, removed or inserted into the arrangedSubviews array, or whenever one of the arranged subviews’s hidden property changes.

SWIFT 3:

// Appears to remove the first arranged view from the stack.
// The view is still inside the stack, it's just no longer visible, and no longer contributes to the layout.
let firstView = stackView.arrangedSubviews[0]
firstView.hidden = true

SWIFT 4:

let firstView = stackView.arrangedSubviews[0]
firstView.isHidden = true