Swift-画虚线、虚线圆
发布时间:2020-12-14 07:05:16 所属栏目:百科 来源:网络整理
导读:代码如下: case .LayerType _XuXian_Circle: self .title = "画虚线" //画虚线 let dotteShapLayer = CAShapeLayer() let mdotteShapePath = CGPathCreateMutable() dotteShapLayer .fillColor = UIColor .clearColor () .CGColor dotteShapLayer .strokeCo
代码如下: 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
效果如下: 虚直线 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |