Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS equivalent for Android View.GONE visibility mode

I'm developing an app for iOS and I'm using the Storyboard with AutoLayout ON. One of my view controllers has a set of 4 buttons, and in certain circumstances i would like to make the first one disappear.

If I use the setHidden:TRUE method the UIButton become invisible but it still obviously take space in the view, and the result is an "hole" which I've not been able to fill making the remaining UIButton to float towards the top of the main view.

In Android I would have simply used View.GONE instead of View.INVISIBLE, but in iOS I'm stuck with this behaviour and I don't want to believe that the only solution is to manually (yes I mean programmatically) move the remaining elements to the top.

I thought I would have been able to do it setting some sort of Constraint to make everything as automatic as it is in Android but I've had no luck.

Before I turn Autolayout OFF, can someone point me to the right direction?

I'm using the IB, but I'm comfortable with programmatic stuff as well.

UPDATE:

Setting the component height to 0 doesn't help as well.

I tried something like this:

UIButton *b;
CGRect frameRect = b.frame;
frameRect.size.height = 0;
b.frame = frameRect;
like image 693
elbuild Avatar asked Jul 25 '13 21:07

elbuild


3 Answers

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]];
like image 153
Deniz Avatar answered Oct 17 '22 20:10

Deniz


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

like image 27
Ucdemir Avatar answered Oct 17 '22 22:10

Ucdemir


add a height constraint to your view as follows:enter image description here

then make an outlet for the height constraint in your viewController file as follows:enter image description here

& then in your viewDidLoad method change constraint height to 0 as follows:

override func viewDidLoad() {
    super.viewDidLoad()
nsLcButtonHeight.constant = 0
}
like image 16
Ajinkya Patil Avatar answered Oct 17 '22 20:10

Ajinkya Patil