给UIView 设置透明度,不影响其他sub views

来源:互联网 发布:服务器硬件检测软件 编辑:程序博客网 时间:2024/04/29 21:01

给UIView 设置透明度,不影响其他sub views

UIView设置了alpha值,但其中的内容也跟着变透明。有没有解决办法?

方法:

1 . 设置background color的颜色中的透明度

[self.testView setBackgroundColor:[UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:0.5]];

设置了color的alpha, 就可以实现背景色有透明度,当其他sub views不受影响

2 . 给color 添加 alpha,或修改alpha的值。

// Returns a color in the same color space as the receiver with the specified alpha component.- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;eg.[view.backgroundColor colorWithAlphaComponent:0.5];

解决。

0 0