使用iOS中的核心图形绘制带有渐变的外半圆? [英] draw outer half circle with gradient using core graphics in iOS?

查看:374
本文介绍了使用iOS中的核心图形绘制带有渐变的外半圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS中使用核心图形绘制附加图像中的形状。这可能吗。如果可能,请提供示例代码。

i want to draw a shape like in the attached image using core graphics in iOS. Is this possible. Please provide sample code if it possible.

我想要至少3个形状上的颜色渐变。

I want at least 3 color gradient over the shape.

推荐答案

如果你想在 CGContext 中绘制这个:



使用 + [UIBezierPath bezierPathWithArcCenter:radius:startAngle:endAngle:顺时针:] 创建包含半圆形的路径弧。然后使用 CGPathCreateCopyByStrokingPath 在弧周围创建一个封闭的形状。使用 CGContextAddPath 将此封闭的形状添加到上下文的路径,然后使用 CGContextClip 将剪辑区域设置为粗弧。

If you want to draw this in a CGContext:

Use +[UIBezierPath bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:] to create a path containing a semi-circular arc. Then use CGPathCreateCopyByStrokingPath to create an enclosed shape around the arc. Use CGContextAddPath to add this enclosed shape to your context's path, then use CGContextClip to set the clip region to the thick arc.

使用 CGGradientCreateWithColors 创建一个 CGGradient 彩虹的颜色。使用 CGContextDrawLinearGradient 用渐变填充剪辑区域。

Use CGGradientCreateWithColors to create a CGGradient with your rainbow colors. Use CGContextDrawLinearGradient to fill the clip region with the gradient.

创建 CAGradientLayer 。将图层的 colors 属性设置为彩虹色。将图层的 startPoint 设置为(0,0),将图层的 endPoint 设置为(1,0)。

Create a CAGradientLayer. Set the layer's colors property to your rainbow of colors. Set the layer's startPoint to (0,0) and the layer's endPoint to (1,0).

创建 CAShapeLayer 并将其设置为渐变图层的蒙版。使用 + [UIBezierPath bezierPathWithArcCenter:radius:startAngle:endAngle:顺时针:] CGPathCreateCopyByStrokingPath 创建一个封闭厚的路径arc,并将此路径设置为形状图层的路径

Create a CAShapeLayer and set it as the gradient layer's mask. Use +[UIBezierPath bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:] and CGPathCreateCopyByStrokingPath to create a path enclosing the thick arc, and set this path as the shape layer's path.

这篇关于使用iOS中的核心图形绘制带有渐变的外半圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆