开发者社区> 问答> 正文

我想实现图中的效果,下面一层UIView是黑色半透明的,上面一层的UIImageView是不透明的,该怎么实现?

该图是直接设置UIView透明度为0.7的效果
screenshot

展开
收起
a123456678 2016-07-28 14:52:43 3141 0
1 条回答
写回答
取消 提交回答
  • soeasy, 你只要设置你的半透明的黑色背景的background.

    blackView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    

    就OK啦。

        UIView *blackView = [UIView new];
        blackView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        [self.view addSubview:blackView];
    
        [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(self.view);
            make.center.equalTo(self.view);
        }];
    
        UIImageView *topImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fenxiang"]];
        [blackView addSubview:topImageView];
    
        [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(blackView).insets(UIEdgeInsetsMake(200, 50, 100, 50));
        }];
    2019-07-17 20:01:24
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载