Can you override a parent UIView's alpha value on one of its subviews?

蓝咒 提交于 2019-12-07 03:28:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!