adding black overlay with 0.3 opacity over UIImageView

后端 未结 6 1326
无人共我
无人共我 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:29

    This is similar to MDT's answer except using CALayer properties:

    UIView *blackOverlay = [[UIView alloc] initWithFrame: imageView.frame];
    blackOverlay.layer.backgroundColor = [[UIColor blackColor] CGColor];
    blackOverlay.layer.opacity = 0.3f;
    [self.view addSubview: blackOverlay];
    

提交回复
热议问题