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.

Nathan Fraenkel
  • 3,422
  • 4
  • 18
  • 21

4 Answers4

33

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.

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76
  • 1
    Thanks man. So - I guess this begs the question: what exactly is the difference between "enabled" and "userInteractionIsEnabled"? – Nathan Fraenkel Jul 10 '13 at 14:17
  • 1
    `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`. – Nirav Gadhiya Jul 10 '13 at 14:51
  • Hope it will answer your next questions. – Nirav Gadhiya Jul 10 '13 at 14:52
  • Totally yeah I appreciate your thorough and in depth response, it was exactly what I was hoping for! – Nathan Fraenkel Jul 10 '13 at 17:53
  • 1
    Does this mean that a view behind a hidden view will receive touches or will they just be lost? – JohnVanDijk Jan 07 '16 at 07:39
  • 1
    Yes, Any view just behind a hidden view will definitely receive touch events – Nirav Gadhiya Jan 07 '16 at 08:26
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.

Andy
  • 717
  • 1
  • 9
  • 24
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.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0

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

Exothug
  • 339
  • 4
  • 18