How to apply Curve at bottom of UIImageView?

前端 未结 2 1800
余生分开走
余生分开走 2020-12-28 10:22

I want to mask and add some curve at bottom of image view. i have try below code .

extension UIImage{
    var roundedImage: UIImage {
        let rect = CGRe         


        
2条回答
  •  萌比男神i
    2020-12-28 10:59

    This will help you to solve your problem

    extension UIImageView{
          var roundedImage: UIImageView {
            let maskLayer = CAShapeLayer(layer: self.layer)
            let bezierPath = UIBezierPath()
            bezierPath.move(to: CGPoint(x:0, y:0))
            bezierPath.addLine(to: CGPoint(x:self.bounds.size.width, y:0))
            bezierPath.addLine(to: CGPoint(x:self.bounds.size.width, y:self.bounds.size.height))
            bezierPath.addQuadCurve(to: CGPoint(x:0, y:self.bounds.size.height), controlPoint: CGPoint(x:self.bounds.size.width/2, y:self.bounds.size.height-self.bounds.size.height*0.3))
            bezierPath.addLine(to: CGPoint(x:0, y:0))
            bezierPath.close()
            maskLayer.path = bezierPath.cgPath
            maskLayer.frame = self.bounds
            maskLayer.masksToBounds = true
            self.layer.mask = maskLayer
            return self
          }
        }
    

    Result

提交回复
热议问题