我一直在尋找這個掙扎一段時間,需要一些幫助。我只想以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