iOS 画虚线

iOS 画虚线_第1张图片
playground
  • 通过Quartz2D画虚线
    func drawDashLine(view: UIView) {
        let dashShapeLayer = CAShapeLayer()
        dashShapeLayer.strokeColor = UIColor.red.cgColor
        dashShapeLayer.lineWidth = 2
        let shapePath = CGMutablePath()
        dashShapeLayer.lineDashPattern = [10,5]
        shapePath.move(to: .init(x: 20, y: 230))
        shapePath.addLine(to: .init(x: 335, y: 230))
        dashShapeLayer.path = shapePath
        view.layer.addSublayer(dashShapeLayer)
    }

你可能感兴趣的:(iOS 画虚线)