Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在objective-C中绘制四分之一圆_Iphone_Objective C - Fatal编程技术网

Iphone 如何在objective-C中绘制四分之一圆

Iphone 如何在objective-C中绘制四分之一圆,iphone,objective-c,Iphone,Objective C,可能重复: 我是iOS开发的初学者。您知道如何使用CoreGraphic绘制这样的图像吗?您可以使用UIBezierPath类,使用方法bezierPathWithArcCenter:radius:StartTangle:endAngle:顺时针绘制圆弧段。看一看 您还需要使用CGContextMoveToPoint/CGContextAddLineToPoint 最后,通过调用路径上的stroke方法来划行 编辑 要绘制内部线条,您可能需要剪裁这些线条:这是通过CGContextClip函数

可能重复:


我是iOS开发的初学者。您知道如何使用CoreGraphic绘制这样的图像吗?

您可以使用
UIBezierPath
类,使用方法
bezierPathWithArcCenter:radius:StartTangle:endAngle:顺时针
绘制圆弧段。看一看

您还需要使用
CGContextMoveToPoint/CGContextAddLineToPoint

最后,通过调用路径上的
stroke
方法来划行

编辑 要绘制内部线条,您可能需要剪裁这些线条:这是通过
CGContextClip
函数完成的,您当然可以使用

void CGContextAddArcToPoint
文件:


这是绘制圆弧部分的代码。一旦画好了,你就可以在里面画线了

#include <math.h>

CGFloat radius = 100;

CGFloat starttime = M_PI/6; //1 pm = 1/6 rad
CGFloat endtime = M_PI;  //6 pm = 1 rad

//draw arc
CGPoint center = CGPointMake(radius,radius);
UIBezierPath *arc = [UIBezierPath bezierPath]; //empty path
[arc moveToPoint:center];
CGPoint next;
next.x = center.x + radius * cos(starttime);
next.y = center.y + radius * sin(starttime);
[arc addLineToPoint:next]; //go one end of arc
[arc addArcWithCenter:center radius:radius startAngle:starttime endAngle:endtime clockwise:YES]; //add the arc
[arc addLineToPoint:center]; //back to center

[[UIColor yellowColor] set];
[arc fill];
#包括
CGFloat半径=100;
CGFloat starttime=M_PI/6//下午1点=1/6拉德
CGFloat endtime=M_PI//下午6点=1拉德
//画弧
CGPoint center=CGPointMake(半径,半径);
UIBezierPath*弧=[UIBezierPath bezierPath]//空路
[弧移动点:中心];
下一步;
next.x=中心.x+半径*cos(起始时间);
next.y=中心.y+半径*sin(起始时间);
[arc addLineToPoint:next]//走弧的一端
[arc ADDARC WITH center:中心半径:半径startAngle:开始时间ENDARGE:结束时间顺时针:是]//添加弧
[arc addLineToPoint:中心]//回到正中
[[UIColor yellowColor]设置];
[电弧填充];

您需要覆盖将用于显示此图形的视图的drawRect方法。

您应该首先查看Stackoverflow是否有答案。谢谢大家帮助我@如果答案对你有帮助,请投票并打勾。