简体   繁体   中英

UIView background

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 its image 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?

This answer gives you two good avenues to explore:

Memory consumption while loading a large image in uiimageview in

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM