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.
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:
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.
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.
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.
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.
That behaves more like Android View.GONE than .hidden(), which only affects visibility.
Choose the Right Technique
Use:
- '
isHiddenfor pure visibility changes' - '
UIStackViewwhen 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 = truealways removes the layout gap. - Fighting Auto Layout instead of modeling visible and hidden constraint states explicitly.
- Using alpha
0when 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.GONEin UIKit when the solution is layout-specific.
Summary
- iOS has no exact universal equivalent to Android
View.GONE. - '
isHiddenhides a view, but layout collapse depends on the container.' - '
UIStackViewgives the closest built-inGONEbehavior.' - With Auto Layout, update constraints to remove the gap.
- Use
removeFromSuperview()only when the view should truly leave the hierarchy.
Related reading
- IOS Facebook SDK - Post Open Graph and show on Timeline without clicking Activity Log
- iOS forces rounded corners and glare on inputs
- iOS Heart rate detection Algorithm
- iOS how can I add a completion block to UIWebView loadRequest?
- iOS How does one animate to new autolayout constraint height
- iOS How to debug freshly launching an app from a URL
- iOS How to detect if a user is subscribed to an auto-renewable subscription
- iOS How to get a proper Month name from a number?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.