22

I have a question about UIView, what's the difference between views hidden, alpha and opaque?

The effect of setting view: hidden = yes and view.alpha = 0.0f is the same.

2 Answers 2

43

The differences are subtle. According to the UIView class reference:

  • opaque tells the system that the view has no transparency and is thus faster to render because calculations for blending can be skipped
  • hidden is boolean property that changes only the visibility of the current view and hides it from ui events.
  • alpha is an animatable property

Setting alpha = 0.0f or hidden = YES has the same visual effect. However using hidden to actually hide a view not only in a graphical sense but also from ui events might result in a more efficient responder chain when you have lots of nested views.

5
  • 18
    +1 Note that UIKit does actually treat very-low alpha elements as hidden for the purposes of UI events. The last time I experimented with it, the threshold was 0.1, but this isn't documented and the specific threshold shouldn't be relied on. But if you animate alpha to 0, it isn't generally necessary to then hide it too.
    – Rob Napier
    Commented Jun 7, 2012 at 2:49
  • In case you're wondering like me, if they are somehow connected, the answer is no. If you set the hidden property to YES, then changing the alpha won't have any visual effect.
    – streem
    Commented Jan 20, 2015 at 10:04
  • It doesn't seem to be the case that the actual hidden property is set to YES when the alpha of a property gets set to 0.0f - you can check with the debugger for yourself
    – Benzy
    Commented Apr 28, 2015 at 12:37
  • 1
    As an addendum, hiding a view in a UIStackView's arranged subviews does not have the same effect as setting the alpha as 0
    – cyril
    Commented Sep 19, 2018 at 5:35
  • I believe that the view with alpha = 0 will still receive gesture events, such as tap or drag.
    – Borzh
    Commented Oct 21, 2019 at 18:55
-3

setting view.hidden = yes will hide the view and view.alpha = 0.0f will set the colors of view alpha 0.0 which will make the view invisible, so both are not same.... :)

1
  • 3
    by setting view.alpha = 0.0f, iOS also sets view.hidden = yes internally, in fact, there is a threshold for alpha (0.1f), for alpha values smaller than this threshold, view.hidden gets set to YES.
    – Scholle
    Commented Jan 12, 2013 at 11:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.