使用 Core Graphics 绘制正方形或包含 png?
我正在为图表制作一个图例,基本上如下所示:
[ ] Line 1
[ ] Line 2
[ ] Line 3
左侧的框需要与图表上的线条颜色相同。
无论如何,我需要知道的是,使用 Core Graphics 绘制方框是否更快,或者只是使用 GIMP 为正方形制作一些 png 并包含它们。
I'm making a legend for a graph that will basically look like this:
[ ] Line 1
[ ] Line 2
[ ] Line 3
The boxes on the left need to be the same color as the lines on the graph.
Anyhow, all I need to know, is whether it's faster to draw the boxes with Core Graphics or just make some pngs with GIMP for the squares and include them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对每个图例使用 UIView 并将其背景颜色设置为您想要的颜色。
Use UIView for each legend and set their background color to the color you want.
这两种方法都足够快,不会产生任何影响。然而,使用 Core Graphics 的优点是您可以更加灵活,例如当您稍后决定需要其他颜色时。另外,您的应用程序将会更小,因为您不必包含 PNG 文件。
Both approaches are fast enough that it shouldn't make a difference. However, using Core Graphics has the advantage that you're a lot more flexible, e.g. when you later decide that you need additional colors. Plus, your app will be smaller, because you don't have to include the PNG files.
画盒子简直就是小菜一碟!我每天都会使用 Core Graphics,特别是因为你可以免费获得视网膜支持。
正如在此示例中所示,您可以仅使用 UIKit 类来完成此操作:
一个警告;使用路径的边缘作为线条的中心进行描边填充。因此,如果您用线宽为 1 点的积分矩形绘制路径,您会得到一条模糊的线。
如果您想要一条 1 点线作为边界,可以通过执行以下操作来解决此问题:
Drawing boxes is a snap! I would go with Core Graphics everyday, especially since you get retina support for free.
As can be seen in this example you can do it using UIKit only classes:
One warning; stroke fills using the edges of the path as the center of the line. So you will get a blurry line if you stroke a path with integral rect with a 1 point line width.
You can remedy this is you want a 1 point line for the border by doing something like this:
在 iOS 上,Core Graphics 使用起来非常简单。在视图的
drawRect:
方法中,只需执行以下操作即可绘制一个正方形:希望这会有所帮助!
On iOS, Core Graphics is quite simple to use. In your view's
drawRect:
method, just do this to draw a square:Hope this helps!