简体   繁体   English

iphone:使视图透明但子视图不透明

[英]iphone: make view transparent but subviews non transparent

I have a Custom UIViewController named A and i want to add its view to another controllers (named B) view as subview. 我有一个名为A的Custom UIViewController,我想将其视图添加到另一个控制器(名为B)视图作为子视图。 A's view contain two buttons as subviews. A的视图包含两个按钮作为子视图。 I want to make A's view transparent but the buttons in it nontransparent. 我想让A的视图透明,但其中的按钮不透明。 I want to know is there any way to do it? 我想知道有什么办法吗?

As of I noticed, 据我注意到,

If a view is set a opacity/alpha value, all its subviews will be applied with that opacity/alpha value. 如果视图设置了不透明度/ alpha值,则其所有子视图都将应用该不透明度/ alpha值。

Try setting the views background color to [UIColor clearColor] 尝试将视图背景颜色设置为[UIColor clearColor]

viewA.backgroundColor = [UIColor clearColor];
[viewA addSubview:button1];
[viewA addSubview:button2];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM