Resize UIImageView

I created a UIImageView with the correct size in the interface builder and included the output in the class file. How can I stop a large jpg from filling the entire screen? I want the image to resize to fit 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.

+4
source share
1 answer

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.

+12
source

All Articles