According to the documentation for UIVIew @property(nonatomic) CGFloat alpha
The value of this property is a floating-point number in the range 0.0 to 1.0, where 0.0 represents totally transparent and 1.0 represents totally opaque. This value affects only the current view and does not affect any of its embedded subviews.
I have a container view configured as follows:
self.myView.backgroundColor = [UIColor blackColor];
self.myView.alpha = 0.5;
[self addSubview:self.myView];
And then add subviews to 'myView'
[myView addSubView anotherView];
anotherView.alpha = 1;
NSLog(@"anotherView alpha = %f",anotherView.alpha); // prints 1.0000 as expected
But 'anotherView' does have alpha on screen (it is not opaque as expected)
How can this be and what can be done?
self.myView
? and add anotherView such like[self.self addSubview:self.myView];
– Antirachiticalpha
value which is all subviews'alpha
values, multiplied. e.g. if the subviews alpha0.8
and the superview's alpha was1.0
, but you change it to0.6
, the subviews alpha is still the same,0.8
. the rendered subview's alpha value is changed only from0.8
to0.48
. – Wilk