Reputation: 11175
I have been trying to implement a circular progress bar in my app, however I have been having a few issues.
This is my code:
override func drawRect(rect: CGRect) {
var ctx = UIGraphicsGetCurrentContext()
var progress: CGFloat = 0.7
var innerRadiusRatio: CGFloat = 0.5
var path: CGMutablePathRef = CGPathCreateMutable()
var startAngle: CGFloat = CGFloat(-M_PI_2)
var endAngle: CGFloat = CGFloat(-M_PI_2) + min(1.0, progress) * CGFloat(M_PI * 2)
var outerRadius: CGFloat = CGRectGetWidth(budgetDisplayView.bounds) * 0.5 - 1.0
var innerRadius: CGFloat = outerRadius * innerRadiusRatio
var center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect))
CGPathAddArc(path, nil, center.x, center.y, innerRadius, startAngle, endAngle, false)
CGPathAddArc(path, nil, center.x, center.y, outerRadius, endAngle, startAngle, true)
CGPathCloseSubpath(path)
CGContextAddPath(ctx, path)
CGContextSaveGState(ctx)
CGContextClip(ctx)
CGContextDrawImage(ctx, budgetDisplayView.bounds, UIImage(named: "RadialProgressFill").CGImage)
CGContextRestoreGState(ctx)
}
I am getting an error - Method does not override any method from its superclass.
Thanks.
Upvotes: 1
Views: 244
Reputation: 25687
This seems to be in a view controller, which doesn't have a bounds
property. This code should be in a UIView
subclass, as your drawRect:
method isn't even going to be called.
Upvotes: 2
Reputation: 93276
It sounds like you're trying to inherit from UIViewController, which has neither a drawRect
method nor a bounds
property. You should be inheriting from UIView instead.
Upvotes: 3