Created
March 10, 2012 19:09
-
-
Save shnhrrsn/2012554 to your computer and use it in GitHub Desktop.
This file contains 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
#import <UIKit/UIKit.h> | |
@interface UIImage (Resizing) | |
- (UIImage*)scaleToSize:(CGSize)size; | |
@end |
This file contains 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
#import "UIImage+Resizing.h" | |
@implementation UIImage (Resizing) | |
- (UIImage*)scaleToSize:(CGSize)size { | |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000 | |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { | |
UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]); | |
} else { | |
UIGraphicsBeginImageContext(size); | |
} | |
#else | |
UIGraphicsBeginImageContext(size); | |
#endif | |
[self drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)]; | |
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return scaledImage; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment