views:

1962

answers:

1
+1  Q: 

UIImageView resize

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.

+1  A: 

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.

Chris