2013-06-03 47 views
-3

如何在iOS應用程序中繪製十字線?繪製十字線與iOS CoreGraphics

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 0.5); // yellow line 
    CGContextBeginPath(context); 
    CGContextMoveToPoint(context, 40.0, 40.0); //start point 

    // Crosshairs go here?!?!?!? 
    // What do I fill in? 

    CGContextClosePath(context); 
    CGContextSetLineWidth(context, 2.0); 
    CGContextStrokePath(context); 
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0); 
    CGContextFillRect(context, rect); 
} 

查看下圖示例圖片。

enter image description here

+2

有你看看石英2D編程指南?所有你需要的是兩條線和一個圓圈。 – rmaddy

+0

是的,我讀過它,但得到的形狀,而不是線條。我不得不轉向其他東西,並認爲我會問。猜測這是令人沮喪的。 :-( –

回答

3

這應該幫助你開始看到你錯過了什麼。你非常接近。添加一個橢圓,你就完成了,但正如其他人所建議的那樣,簡單快速瀏覽Quart2d編程指南或任何Quart2d內容都會顯示所有這些和更多內容。

Drawing a circle

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor); 
    CGContextSetLineWidth(context, 2.0); 
    CGContextBeginPath(context); 
    CGContextMoveToPoint(context, 20, 20); 
    CGContextAddLineToPoint(context, 40, 20); 
    CGContextStrokePath(context); 

    CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor); 
    CGContextSetLineWidth(context, 2.0); 
    CGContextBeginPath(context); 
    CGContextMoveToPoint(context, 30, 10); 
    CGContextAddLineToPoint(context, 30, 30); 
    CGContextStrokePath(context); 

} 
+0

嘿,這很好,謝謝你的幫助!我剛剛加入了 CGContextStrokeEllipseInRect(context,CGRectMake(23.8,14.4,12,12));現在我可以使這些值相對,我真的很感謝你的幫助 –

+1

你是歡迎並提供一些友好的建議;國際海事組織(IMO),所有反對票的理由是你問題的措詞。下一次試着解釋你所嘗試的和你期望的結果,而不是讓它聽起來像是「做我的作業」問題。人們喜歡在這裏提供幫助,但只針對顯示研究已完成的具體問題。 –