iOS: Mask a UIImage using UIBezierPath

后端 未结 1 1189
攒了一身酷
攒了一身酷 2020-12-28 09:47

I am trying to mask an image so that I can give it only two rounded corners. With the code that I have it just adds the mask in white over the image, but doesn\'t seem to a

相关标签:
1条回答
  • 2020-12-28 09:53

    Round two corners in UIView

    As mentioned in the above linked question, you probably need to remove the view from the heirarchy before applying its mask.

    [self.imageView removeFromSuperview];
    self.imageView.layer.mask = maskLayer;
    [self.view addSubview:self.imageView];
    

    Also, your maskLayer has no bounds. You need to set it to the frame (or bounds) of the view you're trying to mask.

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.imageView.frame;
    
    0 讨论(0)
提交回复
热议问题