Swift-画虚线、虚线圆

前端之家收集整理的这篇文章主要介绍了Swift-画虚线、虚线圆前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下:

case .LayerType_XuXian_Circle:
            self.title = "画虚线"
            //画虚线
             let dotteShapLayer = CAShapeLayer()
             let mdotteShapePath = CGPathCreateMutable()
             dotteShapLayer.fillColor = UIColor.clearColor().CGColor
             dotteShapLayer.strokeColor = UIColor.orangeColor().CGColor
             dotteShapLayer.lineWidth = 2.0
             CGPathAddEllipseInRect(mdotteShapePath,nil,CGRectMake(100.0,150.0,200.0,200.0))
             dotteShapLayer.path = mdotteShapePath
             let arr :NSArray = NSArray(array: [10,5])
             dotteShapLayer.lineDashPhase = 1.0
             dotteShapLayer.lineDashPattern = arr as? [NSNumber]
             view.layer.addSublayer(dotteShapLayer)

            break

            case .LayerType_XuXian_Line:
                 self.title = "画虚线直线"
                //画虚线
                let dotteShapLayer = CAShapeLayer()
                let mdotteShapePath = CGPathCreateMutable()
                dotteShapLayer.fillColor = UIColor.clearColor().CGColor
                dotteShapLayer.strokeColor = UIColor.orangeColor().CGColor
                dotteShapLayer.lineWidth = 2.0
                CGPathMoveToPoint(mdotteShapePath,20,100)
                CGPathAddLineToPoint(mdotteShapePath,200)
                CGPathAddLineToPoint(mdotteShapePath,200,200)
                dotteShapLayer.path = mdotteShapePath
                let arr :NSArray = NSArray(array: [10,5])
                dotteShapLayer.lineDashPhase = 1.0
                dotteShapLayer.lineDashPattern = arr as? [NSNumber]
                view.layer.addSublayer(dotteShapLayer)
            break

效果如下:
虚线圆

虚直线

原文链接:https://www.f2er.com/swift/324073.html

猜你在找的Swift相关文章