问题
I have a somewhat transparent view (alpha = 0.6) that has some subviews. I'd like one of the subviews (a UILabel) to be drawn with alpha of 1.0 because the blending makes the text difficult to read but by adding it as a subview of the main view it has adopted its parent's alpha value. Is there a way to override this behavior? I believe I'll have to remove it from the subview but wanted to ask and see if maybe I'm missing something.
回答1:
You are correct. You'll have to move the UILabel out of the transparent view to get it to render as non-transparent.
回答2:
Brian is right. For example :
view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
will make a Black background in alpha 0.6 and other views won't be affected.
回答3:
Another approach which worked easily is to not modify the alpha channel on the UIView. Instead, modify the alpha layer on the backgroundColor object of the UIView.
Of course this depends on why you made the alpha layer transparent, but it worked well for my requirements.
来源:https://stackoverflow.com/questions/1269637/can-you-override-a-parent-uiviews-alpha-value-on-one-of-its-subviews