Scale to fill for UIColor pattern UIImage

Sometimes we need to scale to fill our images to fit in certain image view. This code snippet easly do this. I definitely recommend to you use UIImage category for this. So that you don’t repeat same code again and again.

+ (UIImage *)fitImageWithView:(UIView *)view imageName:(NSString *)imageName {
    if(imageName.length < 1) {
        [NSException raise:@"There is no image name." format:@"Image name is : %@", imageName];
    UIImage *img = nil;
    [[UIImage imageNamed:imageName] drawInRect:view.bounds];
    img = UIGraphicsGetImageFromCurrentImageContext();
    return img;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s