我想绘制一个简单的直尺与Quartz2D的线,只是为了实践。

由于我不知道iPhone上的程序做的矢量图形的想法,也许有人可以指向我一个很好的教程开始?

有帮助吗?

解决方案

作为普拉门指出,石英2D文档是值得一读。此外,课程笔记是可以在线(VoodooPad格式)我iPhone的发展历程,在那里我专门用一类石英2D绘图。该 QuartzExamples 示例应用程序,我创建表演一些更高级的绘图概念,但苹果 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表示黑色。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top