且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

核心图形绘制线与轮廓

更新时间:2023-12-03 23:49:16

iOS 5.0添加了一个新功能 CGPathCreateCopyByStrokingPath / code>这是你想要的。

iOS 5.0 added a new feature CGPathCreateCopyByStrokingPath() that does what you want.

首先为黑色路径创建一个 CGPathRef 然后使用 CGPathCreateCopyByStrokingPath()创建一个副本。

First create a CGPathRef for the black path, and then create a copy of it with CGPathCreateCopyByStrokingPath().

这将给你一个新的路径,

This will give you a new path, which you can fill in black and stroke in red, to get what you want.

此外,创建路径有点慢。你应该避免在执行屏幕绘制时创建路径。所有路径都应存储在RAM中,并且可以在之前开始绘制到屏幕。 drawRect:应该只绘制路径,而不是创建它。

Also, creating paths is a bit slow. You should avoid creating paths while performing screen drawing. All your paths should be stored in RAM and ready to go before you start drawing to the screen. drawRect: should only draw the path, not create it.