iOS
Android
View.GONE
visibility
app development

iOS equivalent for Android View.GONE visibility mode

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Android's View.GONE makes a view invisible and removes it from layout flow so sibling views can take the space. iOS does not have a single property that does exactly the same thing for every layout system. The closest equivalent depends on how your interface is built: with Auto Layout, UIStackView, or manual frames.

isHidden Alone Is Not a Full Equivalent

UIKit gives every UIView an isHidden property:

swift
label.isHidden = true

That hides the view visually, but it does not automatically collapse every layout gap in the same way Android View.GONE does. With basic Auto Layout constraints, the hidden view may still influence the layout unless the surrounding constraints are designed to adapt.

So isHidden is necessary for invisibility, but not always sufficient for layout collapse.

UIStackView Is the Closest Built-In Match

If the hidden view is an arranged subview of a UIStackView, setting isHidden = true is usually the closest behavior to View.GONE. The stack view removes the arranged subview from its layout calculations.

swift
1import UIKit
2
3let stack = UIStackView()
4stack.axis = .vertical
5stack.spacing = 8
6
7let titleLabel = UILabel()
8titleLabel.text = "Title"
9
10let subtitleLabel = UILabel()
11subtitleLabel.text = "Subtitle"
12
13stack.addArrangedSubview(titleLabel)
14stack.addArrangedSubview(subtitleLabel)
15
16subtitleLabel.isHidden = true

Once hidden, the stack closes the gap automatically. If you are building dynamic forms or settings screens, UIStackView is often the easiest UIKit answer.

With Auto Layout, Collapse Constraints Explicitly

Outside UIStackView, the usual solution is to hide the view and also update constraints so the layout can close up.

swift
1@IBOutlet weak var messageLabel: UILabel!
2@IBOutlet weak var messageHeightConstraint: NSLayoutConstraint!
3
4func setMessageVisible(_ visible: Bool) {
5    messageLabel.isHidden = !visible
6    messageHeightConstraint.constant = visible ? 20 : 0
7    view.layoutIfNeeded()
8}

Another pattern is to activate one set of constraints when the view is visible and a different set when it is hidden. That gives you precise control over the final layout.

Manual Layout Can Remove the View Entirely

If you are laying out views manually, you can remove the view from the hierarchy or set its frame to zero and reposition siblings yourself.

swift
badgeView.removeFromSuperview()

That is closest to the semantic meaning of GONE, but it is heavier than simple hiding because the view is no longer attached to the hierarchy.

SwiftUI Has a Similar Pattern

In SwiftUI, there is no direct gone modifier either. If you need layout collapse, the usual approach is conditional rendering so the view is not in the hierarchy at all.

swift
if shouldShowBadge {
    Text("New")
}

That behaves more like Android View.GONE than .hidden(), which only affects visibility.

Choose the Right Technique

Use:

  • 'isHidden for pure visibility changes'
  • 'UIStackView when you want layout collapse with minimal code'
  • constraint updates when using Auto Layout outside a stack view
  • 'removeFromSuperview() when the view is genuinely no longer needed'

There is no universal one-line substitute, because UIKit layout behavior depends on the container and constraint design.

Common Pitfalls

  • Assuming isHidden = true always removes the layout gap.
  • Fighting Auto Layout instead of modeling visible and hidden constraint states explicitly.
  • Using alpha 0 when you actually want the layout to collapse. Alpha only changes appearance.
  • Removing a view from the hierarchy when you only needed a temporary hide.
  • Forgetting to call layout updates after changing constraints.
  • Looking for a property-level clone of View.GONE in UIKit when the solution is layout-specific.

Summary

  • iOS has no exact universal equivalent to Android View.GONE.
  • 'isHidden hides a view, but layout collapse depends on the container.'
  • 'UIStackView gives the closest built-in GONE behavior.'
  • With Auto Layout, update constraints to remove the gap.
  • Use removeFromSuperview() only when the view should truly leave the hierarchy.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.