I am trying to create an animated radial chart that looks like the activity app created by Apple. I provide an image to show what I would like as result:
Do you know how to obtain this result? If you have any idea could you please focus on the following points?
Thank you very much in advance.
Check out my custom control, I tried to make it as close as possible to the Activity app design, and everything is customizable.
https://github.com/maxkonovalov/MKRingProgressView
The basic idea behind the algorithm is quite simple.
To draw arc line with changing color:
You can use a prerendered image from Photoshop or generate your own dynamically. I use a gradient image generator from here: https://github.com/maxkonovalov/MKGradientView.
CGContextSaveGState(ctx)
CGContextAddPath(ctx, arcPath)
CGContextClip(ctx)
CGContextDrawImage(ctx, gradientRect, gradientImage)
CGContextRestoreGState(ctx)
Drawing the shadow is even simpler:
I draw a circle shape matching arc's end for the shadow.
CGContextSetShadow(ctx, offset, shadowRadius)
CGContextAddPath(ctx, shadowPath)
CGContextSetFillColorWithColor(ctx, shadowColor)
CGContextFillPath(ctx)
CGContextSaveGState(ctx)
CGContextAddPath(ctx, circlePath)
CGContextClip(ctx)
// Draw shadow...
CGContextRestoreGState(ctx)
And the final result looks like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With