iOS设置父view的透明度,使子view不透明

一.问题描述:

项目中遇到添加一个黑色透明的遮罩,在遮罩上添加子控件,使用下列方法添加,子控件也变成透明的

    UIView *blackV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HIGHT)];
    blackV.backgroundColor = [UIColor blackColor];
    blackV.alpha = 0.7;

二.解决方法

1.只设置黑白背景色

blackV.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];

2.设置任意颜色的背景色

1)

blackV.backgroundColor = [UIColor colorWithRed:122/255.0 green:123/255.0 blue:234/255.0 alpha:0.7];

2)

blackV.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.7];



你可能感兴趣的:(iOS开发)