UIImage | Techbirds

A UIImage is an object representing image data. A UIImage is typically displayed inside a UIImageView: exam: UIImage *bgImage = [UIImage imageNamed:@”background.jpg”];

UIImageView *imgView = (UIImageView *)[self.view viewWithTag:20];

imgView.image = bgImage; // display the bgImage data inside the imgView

The simplest way to load an image is with the imageNamed method, however this loads the data into memory and (generally) doesn’t release it, so this is only ideal for small, frequently-used images.
UIImage *bgImage = [UIImage imageNamed:@”background.jpg”];

Use imageWithContentsOfFile to read image data from a file. This method doesn’t cache the image to memory.
UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”background” ofType:@”jpg”]]

Patterned Backgrounds You can use an image as a repeating background pattern for a UIView with this code (add to your view controller’s viewDidLoad method): exam:

self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@”denim.jpg”]];

430 total views, 1 views today

Share this Onfacebook-1207630twitter-5090743linkedin-9357588google-5643796