Core Graphics Vs图像用于自定义按钮 [英] Core Graphics Vs Images for a custom button

查看:114
本文介绍了Core Graphics Vs图像用于自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该何时使用核心图形而不是图像来制作自定义UIButton?
核心图形更快吗?除了分辨率独立性,还有其他任何主要好处吗?

When should I go with core graphics over images for making a custom UIButton? Is core graphics faster? Other than resolution independence, are there any other major benefits?

推荐答案

核心图形的优点:


  • 绘制按钮的代码可能小于图像文件。

  • 允许动态修改,轻​​微更改而不添加完整的秒图片。

  • 正如您所提到的,独立于分辨率。

  • 内存密集程度较低(不会分配内存来容纳每个像素)。

  • Code for drawing a button will probably be smaller than an image file.
  • Allows dynamic modification, slight changes without adding a complete second image.
  • As you mentioned, resolution independent.
  • Less memory intensive (doesn't allocate memory to hold every pixel).

图像优点:


  • 创建图像编辑器通常比编写完美绘制代码的代码更简单。 (如果你使用纯色以外的任何东西,它可能很多更简单。)

  • 编辑器可以让你事先看到图像而无需重新编译。

  • 更容易使用其他内置对象(即,您可以将其作为UIButton的背景)。

  • Creating the image in an editor will usually be simpler than writing code which draws it perfectly. (If you use anything other than solid colors, it could be much simpler.)
  • The editor will let you see the image beforehand without recompiling.
  • Easier to work with other built in objects (i.e., you can make it the background of a UIButton).

至于跑步时间,我不确定。我猜想CG对于简单绘图会更快,大多数像素都没有改变,但对于更复杂的绘图,大多数像素都会被更改,图像会更快(假设你使用PNG格式,那么它会得到优化否则,CG可能总是更快。)

As for running time, I am not sure. I would guess that CG would be faster for simple drawing, where most of the pixels aren't changed, but images would be faster for more complex drawing where most of the pixels are changed (Assuming you use the PNG format, so it gets optomized. Otherwise, CG would probably always be faster).

作为妥协,你可以画一次图像,并使用该图像进行绘图。这样您就可以从中获得一些好处。

As a compromise, you could draw into an image once, and use that image for future drawing. This would allow you to get some of the benefits from each.

这篇关于Core Graphics Vs图像用于自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆