Swift--UIBezierPath 绘制图形

    func drawBack() {
        //// Color Declarations
        let strokeColor = color
     
        let bezierPath = UIBezierPath()
        bezierPath.move(to: CGPoint(x: frame.minX + 25 + 12 , y: frame.minY + 50))
        bezierPath.addLine(to: CGPoint(x: frame.minX + 0.47 * frame.width, y: frame.minY + 50))
        bezierPath.addLine(to: CGPoint(x: frame.minX + 0.5 * frame.width, y: frame.minY + 50 - 30))
        bezierPath.addLine(to: CGPoint(x: frame.minX + 0.53 * frame.width, y: frame.minY + 50))
        bezierPath.addLine(to: CGPoint(x: frame.maxX - 25 - 12 , y: frame.minY + 50))
        bezierPath.addArc(withCenter: CGPoint(x: frame.maxX - 25 - 12, y: frame.minY + 50 + 12), radius: 12, startAngle: 1.5 * .pi, endAngle: 0, clockwise: true)
        bezierPath.addLine(to: CGPoint(x: frame.maxX - 25, y: frame.maxY - 50 - 12))
        bezierPath.addArc(withCenter: CGPoint(x: frame.maxX - 25 - 12, y: frame.maxY - 50 - 12), radius: 12, startAngle: 0, endAngle: 0.5 * .pi, clockwise: true)
        bezierPath.addLine(to: CGPoint(x: frame.minX + 25 + 12 , y: frame.maxY - 50))
        bezierPath.addArc(withCenter: CGPoint(x: frame.minX + 25 + 12, y: frame.maxY - 50 - 12), radius: 12, startAngle: 0.5 * .pi, endAngle: 1 * .pi, clockwise: true)
        bezierPath.addLine(to: CGPoint(x: frame.minX + 25 , y: frame.minY + 50 + 12))
        bezierPath.addArc(withCenter: CGPoint(x: frame.minX + 25 + 12, y: frame.minY + 50 + 12), radius: 12, startAngle: 1 * .pi, endAngle: 1.5 * .pi, clockwise: true)
        bezierPath.addLine(to: CGPoint(x: frame.minX + 25 + 12 , y: frame.minY + 50))
        bezierPath.close()
        strokeColor.setStroke()
        UIColor.white.setFill() // 所绘制的曲线围起来的区域设置颜色
        bezierPath.fill() //填充
        bezierPath.lineWidth = 3.5
        bezierPath.stroke()
    }

//调用代码
    override func draw(_ rect: CGRect) {
        drawBack()
    }

Swift--UIBezierPath 绘制图形_第1张图片

你可能感兴趣的:(常识原理)