/**
* 加载图片
*
* @param name 图片名
*/
+ (UIImage *)imageWithName:(NSString *)name;
/**
* 返回一张自由拉伸的图片
*/
+ (UIImage *)resizedImageWithName:(NSString *)name;
+ (UIImage *)resizedImageWithName:(NSString *)name left:(CGFloat)left top:(CGFloat)top;
@end
@implementation UIImage (MJ)
+ (UIImage *)imageWithName:(NSString *)name
{
if (iOS7) {
NSString *newName = [name stringByAppendingString:@"_os7"];
UIImage *image = [UIImage imageNamed:newName];
if (image == nil) { // 没有_os7后缀的图片
image = [UIImage imageNamed:name];
}
return image;
}
// 非iOS7
return [UIImage imageNamed:name];
}
+ (UIImage *)resizedImageWithName:(NSString *)name
{
return [self resizedImageWithName:name left:0.5 top:0.5];
}
+ (UIImage *)resizedImageWithName:(NSString *)name left:(CGFloat)left top:(CGFloat)top
{
UIImage *image = [self imageWithName:name];
return [image stretchableImageWithLeftCapWidth:image.size.width * left topCapHeight:image.size.height * top];
}
@end
链接: http://pan.baidu.com/s/1DbCYy 密码: 5hex