11

I have a UIImage that is much smaller than the UIImageView I am applying it too, I would like to know how to scale the UIImage to fit the width of the UIImageView but keep the width x height ratio of the original small image.

This is what my code looks like pre any sort of scaling

playerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 222.0, self.playerView.frame.size.width-20, 245.0)];
playerImageView.contentMode = UIViewContentModeBottom;
UIImage *placeholderImage = [UIImage imageNamed: @"placeHolderVault.png"];
[playerImageView setImage:placeholderImage];
halfer
  • 19,824
  • 17
  • 99
  • 186
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183

1 Answers1

15

Use the proper contentMode.

playerImageView.contentMode = UIViewContentModeScaleAspectFit;
Mundi
  • 79,884
  • 17
  • 117
  • 140