当前位置 博文首页 > xixi:解决 veiw 之间 因为父view alpha 等于0 导致全部透明的

    xixi:解决 veiw 之间 因为父view alpha 等于0 导致全部透明的

    作者:[db:作者] 时间:2021-08-07 15:36

    首先 先看一段代码,矛盾的起因, 因为父view 的alpha= 0 ,而又想让子view 能够显示出来,不受父view的alpha=0 的影响。

        UIView *view = [[UIView alloc] init];
    ??? view.backgroundColor = [UIColor redColor];
    ??? //因为下面的label 没有显示 是因为父view的alpha = 0
    ??? view.alpha = 0;
    ??? view.frame = CGRectMake(30, 100, 200, 200);
    ??? [self.view addSubview:view];
    ?? ?
    ?? ?
    ??? UILabel *label = [[UILabel alloc] init];
    ??? label.frame = CGRectMake(10, 10, 50, 50);
    ??? label.backgroundColor = [UIColor blueColor];
    ??? [view addSubview:label];
    
    
    

    那么下面的这段代码就是 利用 backgroundColor 来处理


        UIView *view = [[UIView alloc] init];
        //red, green, blue 的值 随意填, 关键的是 alpha 要为 0
        view.backgroundColor = [UIColor colorWithRed:0.1f green:0.1f blue:0.1f alpha:0];
        view.frame = CGRectMake(30, 100, 200, 200);
        [self.view addSubview:view];
        
        
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(10, 10, 50, 50);
        label.backgroundColor = [UIColor blueColor];
        [view addSubview:label];
    


    cs