clip-masking uiview with CAShapeLayer and UIBezierPath

后端 未结 3 823
轻奢々
轻奢々 2021-01-04 21:10

I have a problem clipping a view using CAShapeLayer-UIBezierPath , I want to clip the content but I end up getting a stroke (frame) with that UIBezierPath , This is my code

3条回答
  •  青春惊慌失措
    2021-01-04 21:46

    as rob mayoff said You can do this easily by setting your view's layer mask to a CAShapeLayer.

    UIBezierPath *myClippingPath = ...
    CAShapeLayer *mask           = [CAShapeLayer layer];
    mask.path                    = myClippingPath.CGPath;
    myView.layer.mask            = mask;
    

    In Swift

    let myClippingPath = UIBezierPath( ... )
    let mask           = CAShapeLayer()
    mask.path          = myClippingPath.CGPath
    myView.layer.mask         = mask
    

提交回复
热议问题