Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scale UIImage using width and keep ratio [duplicate]

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];
like image 311
HurkNburkS Avatar asked Jan 14 '14 09:01

HurkNburkS


1 Answers

Use the proper contentMode.

playerImageView.contentMode = UIViewContentModeScaleAspectFit;
like image 139
Mundi Avatar answered Sep 28 '22 07:09

Mundi