我想用 Quartz2D 画一把简单的尺子的线条,仅供练习。
由于我不知道如何在 iPhone 上以编程方式制作矢量图形,也许有人可以给我指点一个好的入门教程?
正如普拉门指出的那样,石英 2D 文档 https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html值得一读。另外,课程笔记可以在线获取 http://www.sunsetlakesoftware.com/sites/default/files/AdvancediPhoneApps.zip(VoodooPad 格式)用于我的 iPhone 开发课程,我将整个课程用于 Quartz 2D 绘图。这石英示例 http://www.sunsetlakesoftware.com/sites/default/files/QuartzExamples.zip我创建的示例应用程序显示了一些更高级的绘图概念,但是 Apple 的石英演示 https://developer.apple.com/library/archive/samplecode/QuartzDemo/Introduction/Intro.html示例是一个更好的起点,可以了解如何进行简单的绘图。
作为为标尺绘制刻度的示例,以下是我用来执行类似操作的代码:
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);
where currentHeight
是要覆盖的区域的高度,并且[MyView blackColor]
只是返回一个表示黑色的 CGColorRef。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)