2010-03-28 31 views

回答

4

由於普拉門指出,Quartz 2D documentation是值得一讀。此外,本課程還爲我的iPhone開發課程提供了are available online(VoodooPad格式),我將整個課程都用於Quartz 2D繪圖。我創建的QuartzExamples示例應用程序顯示了一些更高級的繪圖概念,但Apple的QuartzDemo示例是一個更好的地方,可以開始瞭解如何執行簡單繪製。

拉絲的例子蜱的一把尺子,以下是我用來做同樣的事情代碼:

NSInteger minorTickCounter = majorTickInterval; 
NSInteger totalNumberOfTicks = totalTravelRangeInMicrons/minorTickSpacingInMicrons; 
CGFloat minorTickSpacingInPixels = currentHeight/(CGFloat)totalNumberOfTicks; 

CGContextSetStrokeColorWithColor(context, [MyView blackColor]); 

for (NSInteger currentTickNumber = 0; currentTickNumber < totalNumberOfTicks; currentTickNumber++) 
{ 
    CGContextMoveToPoint(context, leftEdgeForTicks + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5); 

    minorTickCounter++; 
    if (minorTickCounter >= majorTickInterval) 
    { 
     CGContextAddLineToPoint(context, round(leftEdgeForTicks + majorTickLength) + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5); 
     minorTickCounter = 0;    
    } 
    else 
    { 
     CGContextAddLineToPoint(context, round(leftEdgeForTicks + minorTickLength) + 0.5, round(currentTickNumber * minorTickSpacingInPixels) + 0.5); 
    } 

} 

CGContextStrokePath(context); 

其中currentHeight是區域的高度覆蓋,並[MyView blackColor]只是返回一個代表黑色的CGColorRef。

+0

酷東西的男人。謝謝。 – dontWatchMyProfile 2010-04-01 20:24:59

+0

代碼不清晰(作爲語法),請讓示例更清晰,如何創建併爲該上下文設置高度......等 – 2015-11-09 14:43:00