Skip to content

Instantly share code, notes, and snippets.

@bigeyex
Created December 18, 2015 12:35
Show Gist options
  • Save bigeyex/e5a2ba7a27930415ac86 to your computer and use it in GitHub Desktop.
Save bigeyex/e5a2ba7a27930415ac86 to your computer and use it in GitHub Desktop.
UIImage+Resize.h - resize UIImages
#import <Foundation/Foundation.h>
@interface UIImage (Resize)
- (UIImage *)resizeTo:(CGSize)newSize;
@end
#import "UIImage+Resize.h"
@implementation UIImage (Resize)
- (UIImage *)resizeTo:(CGSize)newSize
{
CGFloat scale = [[UIScreen mainScreen]scale];
/*You can remove the below comment if you dont want to scale the image in retina device .Dont forget to comment UIGraphicsBeginImageContextWithOptions*/
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
[self drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment