美文网首页
iOS 解决 veiw 之间 因为父view alpha 等于0

iOS 解决 veiw 之间 因为父view alpha 等于0

作者: 村雨灬龑 | 来源:发表于2018-08-21 10:03 被阅读0次

首先 先看一段代码,矛盾的起因, 因为父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];

相关文章

网友评论

      本文标题:iOS 解决 veiw 之间 因为父view alpha 等于0

      本文链接:https://www.haomeiwen.com/subject/fpppxftx.html