diff options
author | Vitaly Takmazov | 2014-02-01 19:47:09 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2014-02-01 19:47:09 +0400 |
commit | 6ee0e66d56f02c4b534dd83fca24cb0c1f408f06 (patch) | |
tree | 6935c24fd232f38baf68cc59e61bef681eb8b588 /Juick/UIImage+Utils.m | |
parent | 297dfab2b57a00a7a40328d68af30dc6b32d3320 (diff) |
0ld-zkul hax0r manual cell layout
Diffstat (limited to 'Juick/UIImage+Utils.m')
-rw-r--r-- | Juick/UIImage+Utils.m | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Juick/UIImage+Utils.m b/Juick/UIImage+Utils.m new file mode 100644 index 0000000..4617c65 --- /dev/null +++ b/Juick/UIImage+Utils.m @@ -0,0 +1,69 @@ +// +// UIImage+Utils.m +// Juick +// +// Created by Vitaly on 01.02.14. +// Copyright (c) 2014 com.juick. All rights reserved. +// + +#import "UIImage+Utils.h" + +@implementation UIImage (Utils) + ++ (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width covertToHeight:(float)height { + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContext(size); + [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; + UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return newimage; +} + ++ (UIImage*)imageWithImage:(UIImage *)image convertToHeight:(float)height { + float ratio = image.size.height / height; + float width = image.size.width / ratio; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContext(size); + [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; + UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return newimage; +} + ++ (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width { + float ratio = image.size.width / width; + float height = image.size.height / ratio; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContext(size); + [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; + UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return newimage; +} + ++ (UIImage*)imageWithImage:(UIImage *)image fitInsideWidth:(float)width fitInsideHeight:(float)height { + if (image.size.height >= image.size.width) { + return [UIImage imageWithImage:image convertToWidth:width]; + } else { + return [UIImage imageWithImage:image convertToHeight:height]; + } +} + ++ (UIImage*)imageWithImage:(UIImage *)image fitOutsideWidth:(float)width fitOutsideHeight:(float)height { + if (image.size.height >= image.size.width) { + return [UIImage imageWithImage:image convertToHeight:height]; + } else { + return [UIImage imageWithImage:image convertToWidth:width]; + } +} + ++ (UIImage*)imageWithImage:(UIImage *)image cropToWidth:(float)width cropToHeight:(float)height { + CGSize size = [image size]; + CGRect rect = CGRectMake(((size.width-width) / 2.0f), ((size.height-height) / 2.0f), width, height); + CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect); + UIImage * img = [UIImage imageWithCGImage:imageRef]; + CGImageRelease(imageRef); + return img; +} + +@end |