Displaying An Image From A Design Time File

Drag the image file into the resources folder of your project (from Finder into Xcode, not within Finder)

Open the XIB file, drag an ImageView onto it.

In the inspector attributes tab:

Select the image file

Set the mode

In the inspector size tab:

Set the red anchor links as desired (typically all on for an image – watch the animation to see how they affect the image when the view size changes)

Image Display Modes

Aspect Fit

Will display entire image, creating blank areas in one axis if needed

Aspect Fill

Will display entire image in one axis and will clip image in other axis if needed.

Updating An ImageView From Code

In #ViewController.h

	IBOutlet UIImageView *imageView;
In #ViewController.m

//If view could be unloaded
//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
	[super viewDidUnload];

	[imageView release];
	imageView = nil;

//********** DEALLOC **********
- (void)dealloc
	[imageView release];

	[super dealloc];

//To display an image from filename:
        [imgBackground setImage:[UIImage imageNamed:@"fileName.png"]];
        [imgBackground setImage:[UIImage imageWithContentsOfFile:imageFilename]];

	UIImage *imageToDisplay = ...
	[imageView setImage:imageToDisplay];

//To clear the image:
	[imageView setImage:nil];

Open the XIB file, drag an ImageView onto it.

Right click ‘File Owner’ and drag the imageView outlet onto the UIImageView to connect it