CAShapeLayer
의 경계를 설정해야합니까?CAShapeLayer - 경계
모양 레이어를 만들고이를 UIBezierPath
경로를 지정하면 모양이보기 크기의 단순한 원입니다.
레이어에 position
또는 bounds
을 설정하지 않았습니다. 틀린가요?
class View: UIView {
...
var backgroundLayer: CAShapeLayer!
func setup() {
// call from init
backgroundLayer = CAShapeLayer()
backgroundLayer.strokeColor = UIColor.redColor()
backgroundLayer.lineWidth = 3
backgroundLayer.fillColor = UIColor.clearColor().CGColor
layer.addSublayer(backgroundLayer)
...
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundLayer?.path = circlePath(100)
...
}
func circlePath(progress: Int) -> CGPath {
let path = UIBezierPath()
let inverseProgress = 1 - CGFloat(progress)/100
let endAngleOffset = CGFloat(2 * M_PI) * inverseProgress
path.addArcWithCenter(localCenter, radius: radius, startAngle: CGFloat(-M_PI), endAngle: CGFloat(M_PI) - endAngleOffset, clockwise: true)
return path.CGPath
}
...
}
맑음. –