本文介绍了对于更便宜的颜色条带:UIView 或 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在您的 UI 设计中,您需要一个纯色矩形.当然,您可以使用 UIImageView 对象并将其连接到图像,但在某些情况下,直接放入 UIView 并设置背景颜色可能会更快更容易.

Suppose in your UI design, you need a rectangle of solid color. Of course you could use a UIImageView object and hook it up to an image, but in some cases it might be quicker and easier to just drop in a UIView and set the background color.

我的问题是在内存和性能方面哪个更便宜.我的直觉是空 UIView 比图像更容易渲染,图像必须加载其文件并将位存储在内存中.

My question is with regard to which is cheaper in terms of memory and performance. My gut is that an empty UIView is easier to render than an image, whose file must be loaded and bits stored in memory.

有人可以谈谈吗?非常感谢!

Can anyone speak to this? Many thanks!

推荐答案

设置 UIViewbackgroundColor 比使用 UIImageView 更快/更便宜code>,原因很明显:您不必创建或加载图像,窗口服务器不必保留图像的副本,并且窗口服务器用其背景颜色填充视图的代码是当然至少和它用缩放的 1x1 图像填充视图的代码一样快.

Setting the backgroundColor of a UIView is faster/cheaper than using a UIImageView, for the obvious reasons: you don't have to create or load an image, the window server doesn't have to keep a copy of the image around, and the window server's code for filling a view with its background color is certainly at least as fast as its code for filling a view with a scaled 1x1 image.

这篇关于对于更便宜的颜色条带:UIView 或 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 10:11