圈子进度查看活动应用程序 [英] Circle Progress View like activity app
问题描述
我正在尝试创建一个动画的子午线图表,看起来像Apple创建的活动应用程序。我提供了一个图像来显示我想要的结果:
您知道如何获得此结果吗?如果您有任何想法,请关注以下几点?
- 在每个圆圈内创建渐变
- 在圆圈的头部创建阴影
非常感谢您提前。
检查我的自定义控件,我尽量让它尽可能接近Activity应用程序设计,并且所有内容都可以自定义。
Yo你可以使用Photoshop中的预呈现图像或动态生成自己的图像。我从这里使用渐变图像生成器:
CGContextSaveGState(ctx)
CGContextAddPath(ctx ,arcPath)
CGContextClip(ctx)
CGContextDrawImage(ctx,gradientRect,gradientImage)
CGContextRestoreGState(ctx)
绘制阴影更简单:
- 在您的背后绘制阴影进度弧(此处显示50%不透明度)
我画了一个圆圈e匹配arc的阴影结束。
CGContextSetShadow(ctx,offset,shadowRadius)
CGContextAddPath(ctx,shadowPath)
CGContextSetFillColorWithColor(ctx,shadowColor)
CGContextFillPath(ctx)
- 剪影以适应进度圈
CGContextSaveGState(ctx)
CGContextAddPath(ctx,circlePath)
CGContextClip(ctx)
//绘制阴影...
CGContextRestoreGState(ctx)
最终结果如下这个:
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?
- Create the gradient inside each circle
- Create the shadow on the head of the circle
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:
- Generate a conical gradient image
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.
- Clip gradient image to show only the arc
CGContextSaveGState(ctx)
CGContextAddPath(ctx, arcPath)
CGContextClip(ctx)
CGContextDrawImage(ctx, gradientRect, gradientImage)
CGContextRestoreGState(ctx)
Drawing the shadow is even simpler:
- Draw shadow behind your progress arc (shown with 50% opacity here)
I draw a circle shape matching arc's end for the shadow.
CGContextSetShadow(ctx, offset, shadowRadius)
CGContextAddPath(ctx, shadowPath)
CGContextSetFillColorWithColor(ctx, shadowColor)
CGContextFillPath(ctx)
- Clip the shadow to fit into the progress circle
CGContextSaveGState(ctx)
CGContextAddPath(ctx, circlePath)
CGContextClip(ctx)
// Draw shadow...
CGContextRestoreGState(ctx)
And the final result looks like this:
这篇关于圈子进度查看活动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!