UIView背景
假设我想创建一个自定义组件作为 UIView 子类,并且我想允许将图像设置为背景(为了这个问题,假设一个大图像而不是模式)。我有两个选择:
- 创建一个与 UIView 框架一样大的
UIImageView
并设置其image
属性 - 使用
[UIColor colorWithPattern]
创建图案颜色并设置 。
如果您想使用 Interface Builder 并想看看您做了什么,第一个是少数 如果您想使用模式,第二个效果很好,但请记住我们正在谈论一个大图像。
所以我的问题是关于性能和/或最佳实践,之前的哪种方法是考虑性能的最佳方法?例如,假设该组件将通过动画移动。
根据您自己的经验,这种或另一种方法有一些缺点吗?
Let's suppose that I want to create a custom component as UIView subclass, and i want to allow to set an image as background (for the sake of this question suppose one big image not a pattern) . I have two options:
- Create a
UIImageView
large as the UIView frame and set itsimage
property - Create a pattern color with
[UIColor colorWithPattern]
and set as backgroundColor
The first one is handful if you want to work with Interface Builder and want to see what you do. The second works great if you want to use a pattern, but remember we are talking about one big image.
So my question is about performance and/or best practice which one of the previous method is the best thinking about performance? Suppose, for example, this component will be moved around with an animation.
Based on your own experience there are some drawback in one or another approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案为您提供了两个很好的探索途径:
在 uiimageview 中加载大图像时的内存消耗
This answer gives you two good avenues to explore:
Memory consumption while loading a large image in uiimageview in