I might get down-votes for this question but i am curios and couldn't find any explanation. So I am gonna post it here.
My question is, I have to show custom separator image in my custom cell. If I simply set background colour of imageView
, rather than setting UIImage
, is it better approach?
Here is the example screenshot to explain my question.
In this screenshot, I have black and grey separators.
[barImage setBackgroundColor:[UIColor blackColor]];
[greyBarImage setBackgroundColor:[UIColor greyColor]];
OR
[barImage setImage:[UIImage imageNamed:@"black.png"]];
[greyBarImage setImage:[UIImage imageNamed:@"grey.png"]];
Now, which one is better? All I know the imageNamed:
is bit slower and we should avoid, but I am not sure about that.
EDIT:
This is what I know after posting this question:
Setting Image:
UIImageView
Setting background colour:
UIImageView
, so the whole imageView
will be opaque and will respond to touches. UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
A view that displays a single image or a sequence of animated images in your interface.
Whenever you want an image in a view controller, you use a UIImageView. A UIImageView contains a UIImage, which is the raw bitmap, and allows you to configure how you want to scale or crop the image.
- parameter color: The color of the background */ convenience init(withBackground color: UIColor) { let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1) UIGraphicsBeginImageContext(rect. size); let context:CGContext = UIGraphicsGetCurrentContext()!; context. setFillColor(color.
If both solution works for you the setting background colour would be better than setting image
[barImage setBackgroundColor:[UIColor blackColor]];
[greyBarImage setBackgroundColor:[UIColor greyColor]];
As this will
1.Save your app resources(Image).
2.Avoid runtime image loading issue(in case of rename replace).
Please refer Simple drawing app and Image drawing app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With