标签:
1. 问题:图片过小,需要放大到合适尺寸
//对图片进行压缩
defaultStatusImg1 = [self scaleImage:defaultStatusImg1 toScale:1.5f];
2. 问题:图片失真
//图片失真
defaultStatusImg1 = [UIImage_Extend imageWithColor:[UIColor clearColor] withImage:defaultStatusImg1 withSize:itemRect.size withOffsetPoint:CGPointMake(34.f,5.f)];//offsetPoint可以使图片和文字对齐
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));
[image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
前提:
1.导入framework-libuiframework.a
2.创建UIImage_Extend:
// UIImage+Extend.h
#import <Foundation/Foundation.h>
@interface UIImage_Extend : NSObject
+(UIImage*)imageCroppedToFitSize:(CGSize)size withFileName:(NSString*)fileName;
+(UIImage *)imageCroppedToFitSize:(CGSize)size withData:(UIImage*)srcData;
+(UIImage*)imageCroppedToFitSizeII:(CGSize)size withData:(UIImage *)srcData;
+(UIImage*)imageCroppedToFitSizeII:(CGSize)size withFileName:(NSString*)fileName;
+(UIImage*)imageScaleToFitSize:(CGSize)size withFileName:(NSString*)fileName;
+(UIImage*)imageScaleToFitSize:(CGSize)size withData:(UIImage*)srcData;
+(UIImage *)makeRoundCornerImage:(UIImage*)img :(int) cornerWidth :(int) cornerHeight;
+(UIImage *)imageWithColor:(UIColor *)color;
+(UIImage *)imageWithColor:(UIColor *)color withImage:(UIImage*)contentImage withSize:(CGSize)size;
+(UIImage *)imageWithColor:(UIColor *)color withImage:(UIImage*)contentImage withSize:(CGSize)size withOffsetPoint: (CGPoint)point;
@end
标签:
原文地址:http://www.cnblogs.com/yuyu-2012/p/4977855.html