UIView alpha vs. UIColor alpha

Viewed 15209

I would like to know the difference between:

  • Assigning my UIView a color with <1 alpha vs
  • Assigning it a non-transparent color but giving the UIView a <1 alpha value.

On the screenshot I have made two UIViews with two black (alpha = 1.0) UILabels on top of each:

Two UIView's with same color but 0.5 alpha on UIView and bg. color and a third one with alpha 1

Assume a macro _RGB is defined before:

#define _RGB(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

and then here is the code::

[_view1 setBackgroundColor:_RGB(255, 0, 0, 1)];
[_view1 setAlpha:0.5];

[_view2 setBackgroundColor:_RGB(255, 0, 0, 0.5)];
[_view2 setAlpha:1];

[_view3 setBackgroundColor:_RGB(255, 0, 0, 1)];
[_view3 setAlpha:1];

I can see only one difference visually: Changing view's own alpha instead of bg color's, affects the subviews as well. But other than that is there any difference in functionality that I should consider? (eg. On animations, layers, etc.)

1 Answers
Related