adding black overlay with 0.3 opacity over UIImageView

后端 未结 6 1319
无人共我
无人共我 2021-01-31 10:52

I have a UIImageView and I wanted to add a black overlay on top of it. What is the best way of doing this without having to override drawRect? I was thinking of adding a CALayer

6条回答
  •  既然无缘
    2021-01-31 11:43

    Something like this?

    UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, myImageView.frame.size.width, myImageView.frame.size.height / 2)];
    [overlay setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]];
    [myImageView addSubview:overlay];
    

提交回复
热议问题