ios uibutton hidden: does this automatically make the button disabled?
Asked Answered
C

4

20

I just have a knowledge question about UIButtons / iOS in general.

Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?

Just curious. Thanks y'all.

Cubitiere answered 9/7, 2013 at 13:43 Comment(3)
since it is not visible, how do you know it is not clickable?Joijoice
It surely would have been quicker to test this rather than write a question and wait for a response ;)Penniepenniless
it was more for curiosity's sake - so I guess I wasn't quite that curiousCubitiere
C
34

UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.

Class reference of UIView says if any view is hidden then it will not receive input events

Class reference of UIView says:

A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect of hiding those subviews and any view descendants they might have. This effect is implicit and does not alter the hidden state of the receiver’s descendants.

you can find this over Here.

Chem answered 9/7, 2013 at 13:53 Comment(6)
Thanks man. So - I guess this begs the question: what exactly is the difference between "enabled" and "userInteractionIsEnabled"?Cubitiere
enabled is not the property of UIView. It is a private property of UIButton. While userInteractionEnabled is the property of UIView which is inherited by UIButton. If userInteractionEnabled is set to NO then it will disable UITouch event of that view or button, while enabled will disable inputs only not UITouch.Chem
Hope it will answer your next questions.Chem
Totally yeah I appreciate your thorough and in depth response, it was exactly what I was hoping for!Cubitiere
Does this mean that a view behind a hidden view will receive touches or will they just be lost?Expense
Yes, Any view just behind a hidden view will definitely receive touch eventsChem
R
2

It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.

Rotz answered 9/7, 2013 at 13:46 Comment(0)
G
1

Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.

Gracious answered 9/7, 2013 at 13:45 Comment(0)
P
0

Not sure. Best way to find out would be an NSLog returning button.hidden

Palais answered 9/7, 2013 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.