UIImageView resize

cocoa-touch, iphone, uiimageview

Solution

In Interface Builder, select your UIImageView and open the Attributes Inspector (Command-1). Change the View Mode to "Aspect Fit".

If you want to do this in code, set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit.

Problem

I've made a UIImageView with the correct size in the interface builder and connected the outlet up in the class file. How can I stop a large jpg from filling the entire screen? I want the image to resize to fit in the frame I made in IB. ``` - (void)viewDidLoad { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"wine" ofType:@"jpg"]; NSData* data = [NSData dataWithContentsOfFile:filePath]; if(data){ photo.image= [[UIImage alloc] initWithData:data]; } [super viewDidLoad]; } ``` THANKS.

Original source