【发布时间】:2017-12-16 19:30:01
【问题描述】:
我一直在尝试使用 Swift 4 在 XCode 9 iOS 11 中为CAShapeLayer 填充颜色,但没有成功。
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 12, startAngle: 0.0, endAngle: CGFloat(Double.pi * 2.0), clockwise: true)
let circleLayer = CAShapeLayer()
circleLayer.path = circlePath.cgPath
circleLayer.fillColor = UIColor.red.cgColor
circleLayer.strokeColor = UIColor.white.cgColor
circleLayer.lineWidth = 1.5
【问题讨论】:
-
首先,检查您是否将其正确添加到视图层。其次,检查您添加它的视图的
frame(例如,使用视图调试器等)。顺便说一句,使用.zero的中心然后从 0 到 2π 有点奇怪(因为大概该圆的四分之三不会在您添加它的视图的框架内)。同样不相关,我建议将endAngle简化为CGFloat.pi * 2或.pi * 2。
标签: ios swift ios11 swift4 cashapelayer