CashApelayer填充颜色Swift 4 Xcode 9 IOS 11不起作用



我一直在尝试使用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

也许,您忘了设置框架。例如:

circleLayer.frame = CGRect(x: 6, y: 6, width: 12, height: 12)

最新更新