美文网首页Swift
UIBezierPath绘制不规则图形

UIBezierPath绘制不规则图形

作者: 不泯iOS | 来源:发表于2021-03-04 17:04 被阅读0次

    参考链接
    效果:


    代码:
    let bezierPath = UIBezierPath()
            bezierPath.move(to: CGPoint(x: 40, y: 40))
            bezierPath.addLine(to: CGPoint(x: 150, y: 40))//添加线条
            bezierPath.addArc(withCenter: CGPoint(x: 170, y: 40), radius: 20, startAngle: CGFloat(-1.0*M_PI), endAngle: CGFloat(-1.5*M_PI), clockwise: false)//添加圆弧
            bezierPath.addLine(to: CGPoint(x: 170, y: 150))
            bezierPath.addArc(withCenter: CGPoint(x: 170, y: 170), radius: 20, startAngle: CGFloat(-0.5*M_PI), endAngle: CGFloat(-M_PI), clockwise: false)
            bezierPath.addLine(to: CGPoint(x: 40, y: 170))
            bezierPath.close()
            let shapeLayer = CAShapeLayer()
            let gradientLayer = CAGradientLayer()
            shapeLayer.path = bezierPath.cgPath
            shapeLayer.fillColor = UIColor.clear.cgColor
            shapeLayer.strokeColor = UIColor.black.cgColor
            self.layer.addSublayer(shapeLayer)
    

    相关文章

      网友评论

        本文标题:UIBezierPath绘制不规则图形

        本文链接:https://www.haomeiwen.com/subject/qupkqltx.html