Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created February 19, 2015 20:57
Show Gist options
  • Save loganwright/e13d367f06174fd47621 to your computer and use it in GitHub Desktop.
Save loganwright/e13d367f06174fd47621 to your computer and use it in GitHub Desktop.
UIImage+Resize
#import <UIKit/UIKit.h>
@interface UIImage (Resize)
- (UIImage *)scaleToSize:(CGSize)size;
@end
#import "UIImage+Resize.h"
@implementation UIImage (Resize)
- (UIImage *)scaleToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Return our new scaled image
return scaledImage;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment