我一直在寻找这个挣扎一段时间,需要一些帮助。我只想以14.4度的间隔从显示屏中心(160,200)画出25条线。我已经使用这行代码在for循环中,其中x是14.4度乘数 -核心图形 - 在一个角度画一条线
UIImage*backgroundImage = [UIImage imageNamed:@"Primate Background Only.png"];
[backgroundImage drawInRect:CGRectMake(0, 0, 320, 480)];
//绘制外圆
rect = CGRectMake(0.0, 35.0, 320.0, 320.0);
CGContextRef contextRef = UIGraphicsGetCurrentContext(); // Get the contextRef
CGContextSetLineWidth (contextRef, 0.5); // Set the border width
CGContextSetRGBFillColor (contextRef, (219.0f/255.0f), (219.0f/255.0f), (219.0f/255.0f), 0.05f); // Set the circle fill color to GREEN
CGContextSetRGBStrokeColor (contextRef, 0.0, 0.0, 0.0, 0.2); // Set the circle border color to BLACK
CGContextFillEllipseInRect (contextRef, rect); // Fill the circle with the fill color
CGContextStrokeEllipseInRect (contextRef, rect); // Draw the circle border
//绘制内圆
rect = CGRectMake(25.0, 60.0, 270.0, 270.0); // Get the contextRef
CGContextSetLineWidth (contextRef, 0.5); // Set the border width
CGContextSetRGBFillColor (contextRef, (219.0f/255.0f), (219.0f/255.0f), (219.0f/255.0f), 0.25f);
CGContextSetRGBStrokeColor (contextRef, 0.0, 0.0, 0.0, 0.2); // Set the circle border color to BLACK
CGContextFillEllipseInRect (contextRef, rect); // Fill the circle with the fill color
CGContextStrokeEllipseInRect (contextRef, rect);
// Draw Segments
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, 0.0);
for (x=1; x<26; x++) {
CGContextSetLineWidth (context, 0.5);
CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 0.25);
CGContextMoveToPoint (context, 160, 200);
CGContextAddLineToPoint (context, (160.0 * (cos((x*14.4)*(M_PI/180)))), (160.0 * (sin((x*14.4)*(M_PI/180))))); // The angle is in degrees
CGContextAddLineToPoint (context, 200, 65);
CGContextAddLineToPoint (context, 160, 200);
CGContextStrokePath(context); // Why is this not showing both line color and infill?
CGContextSetFillColorWithColor (context, [UIColor whiteColor].CGColor);
CGContextFillPath (context);
CGContextRef context = UIGraphicsGetCurrentContext();
}
(我打算在这里发布图片,但它不会允许我!)
有人可以纠正我的trig函数。这意味着从12:00点到24点顺时针画25条线。相反,它只能回退90度,然后返回,所有线路的长度也是一样。
非常感谢
以上是用于绘制丝束外界和内部片段的请求的代码的一个更大的样品。我会尝试下一步上传图片。
三角法看起来很好,你能告诉我们更多的代码吗?迭代'x'的循环等。 – 2011-05-06 16:03:04
古斯塔夫的权利。此外,如果您可以在其他地方上传图片并提供链接,那么具有足够声誉的人可以编辑您的帖子,以便将其放入内联。 – Tommy 2011-05-06 16:44:26
我想重新格式化你的代码,但它太多了...你可以重新格式化它,所以它是可读的吗?除非你试图混淆它故意:) – 2011-05-06 17:32:27