Created
November 7, 2011 06:51
-
-
Save Nub/1344349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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