iOS equivalent for Android View.GONE visibility mode
Solution 1:
Adding a constraint(NSLayoutAttributeHeight) that sets height of the view to 0 worked for me:
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.captchaView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]];
Solution 2:
All of answers on this questions are inefficient.
Best way to equvailent of Android setVisibility:Gone method on iOS is that StackView
first select components then in editor, embed in, Stack View,
connect new stack view with IBOutlet, then:
hidden:
UIView * firstView = self.svViewFontConfigure.arrangedSubviews[0];
firstView.hidden = YES;
visibility:
UIView * firstView = self.svViewFontConfigure.arrangedSubviews[0];
firstView.hidden = NO;
as using stack view, all constraints will be keeped!
Document
Solution 3:
add a height constraint to your view as follows:
then make an outlet for the height constraint in your viewController file as follows:
& then in your viewDidLoad method change constraint height to 0 as follows:
override func viewDidLoad() {
super.viewDidLoad()
nsLcButtonHeight.constant = 0
}
Solution 4:
To achieve Androids.GONE functionality on iOS is to use a UIStackView. After that hide the child by position. (Apples documentation)
SWIFT 4:
let firstView = cell.rootStackView.arrangedSubviews[0]
firstView.isHidden = true // first view gone
It's a table cell example, just put both insides Stack view
and get item for GONE
the child.
Solution 5:
What you can do is to group your views under a stack view. Then when you hide a particular view, the remaining views will be shifted automatically to fill the space.
You may want to check out the Apple Documentation on Stack Views: https://developer.apple.com/reference/uikit/uistackview
or online tutorials such as: https://www.appcoda.com/stack-views-intro/