Skip to content

Instantly share code, notes, and snippets.

@Nub
Created November 7, 2011 06:51
Show Gist options
  • Select an option

  • Save Nub/1344349 to your computer and use it in GitHub Desktop.

Select an option

Save Nub/1344349 to your computer and use it in GitHub Desktop.
//
// UIImage+Additions.m
// SteveJobsTribute
//
// Created by Zachry Thayer on 10/11/11.
// Copyright (c) 2011 Yoshimi Robotics. All rights reserved.
//
#import "UIImage+Additions.h"
@implementation UIImage (Sizing)
- (UIImage*)imageFittingToRect:(CGRect)aRect maintainAspect:(BOOL)maintainAspect{
CGFloat w = aRect.size.width;
CGFloat h = aRect.size.height;
if (maintainAspect) {
if (w > h) {
h *= w/self.size.width;//scale maintaining aspect
}else if(h > w){
w *= h/self.size.height;//scale maintaining aspect
}
}
CGRect drawRect = CGRectMake(0, 0, w, h);
UIGraphicsBeginImageContext(drawRect.size);
[self drawInRect:drawRect];
return UIGraphicsGetImageFromCurrentImageContext();
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment