Reputation: 2317
Out of sheer interest:
Is there any difference, specifically in (theoretic) performance or memory usage between using a UIImage
of 25x25 pixels, square, one color, png on the one hand, or a UIView
of the same size and color?
Consider the Unread bullet in Mail.app
. Would you use an image for that? Or a UIView
with rounded edges?
An image takes more space, and resided in a UIImageview
, and has a resolution dependency, but on the other hand, once it is loaded, it wouldn't make too much difference, would it?
Upvotes: 0
Views: 769
Reputation: 163
An UIImageView
, being a subclass of UIView
, will instantiate a regular view with all the extension that UIKit developers have built to support displaying an image inside a plain UIView. By doing that you're only creating an extended (aka possibly heavier) version of a standard UIView.
That said, using an UIView
for simple UI elements (like Mail.app's bullet icon) will also allow you to forget about the resolution of the graphical asset since you don't have to care about @2x or @3x resolutions resulting also in a smaller project size.
Of course you'll only save kilobytes when it comes to simple shapes, but reusing this pattern all across the app will benefit you exponentially in the long term.
Upvotes: 0
Reputation: 27428
If you use UIImageView
then it requires image. Where if you use UIView
you not need image, so it makes your application light weight
. Second thing, large image takes more memory to load
. So, it is always beneficial to use UIView
instead of image
wherever possible! It keeps your application light weight and can give better performance!
Upvotes: 2