石英弧、填充、描边和路径

发布于 2024-12-21 17:04:47 字数 954 浏览 2 评论 0原文

我必须创建一些位于圆圈一侧的自定义按钮(如右侧图像上的示例:http://dribbble.com/shots/352571-Game-UI-Bottom-Left

我尝试使用以下代码创建基本形状:

CGContextSetLineWidth(context, 2.0);
CGContextAddArc(context, 200, 200, 100, -M_PI_4, M_PI + M_PI_4, 1);
CGContextAddArc(context, 200, 200, 60, M_PI + M_PI_4,-M_PI_4 , 0);
CGContextClosePath(context);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillPath(context);
CGContextAddArc(context, 200, 200, 100, -M_PI_4, M_PI + M_PI_4, 1);
CGContextAddArc(context, 200, 200, 60, M_PI + M_PI_4,-M_PI_4 , 0);
CGContextClosePath(context);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextStrokePath(context);

我从来没有做过一些核心图形(只有一些小东西,比如画一个圆圈之类的东西......)。令人惊讶的是,为了抚摸形状并使其疼痛,我必须重新创建路径。 我想有一些很聪明的方法可以做到这一点,对吗? ;) 因为我在这里,所以我必须在这个形状上绘制一些渐变,以防万一它使整个事情变得复杂;) 谢谢你的帮助

)

I've got to create a few custom buttons that will be on the side of a circle (like this example on the right hand side image : http://dribbble.com/shots/352571-Game-UI-Bottom-Left)

I tried to create the basic shape using this code :

CGContextSetLineWidth(context, 2.0);
CGContextAddArc(context, 200, 200, 100, -M_PI_4, M_PI + M_PI_4, 1);
CGContextAddArc(context, 200, 200, 60, M_PI + M_PI_4,-M_PI_4 , 0);
CGContextClosePath(context);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillPath(context);
CGContextAddArc(context, 200, 200, 100, -M_PI_4, M_PI + M_PI_4, 1);
CGContextAddArc(context, 200, 200, 60, M_PI + M_PI_4,-M_PI_4 , 0);
CGContextClosePath(context);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextStrokePath(context);

I've never done some Core Graphics yet (only small stuff like drawing a circle and stuff...). It seems surprising tha in order to stroke the shape and pain it, I have to recreate the path.
I guess there are some much clever ways to do this right? ;)
Since I'm here, I will have to draw some gradients in this shape, just in case it complicates the whole stuff ;)
Thanks for you help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄傲 2024-12-28 17:04:48

查看以下函数来创建单个路径:

CGPathCreateMutable()
CGPathAddRect()/CGPathAddRects()
CGContextAddPath()

...为了性能,如果要多次绘制该路径,请记住缓存该路径!

Check out the following functions to create a single path:

CGPathCreateMutable()
CGPathAddRect()/CGPathAddRects()
CGContextAddPath()

...and for performance, remember to cache this path if you're going to draw it multiple times!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文