xcode UIImage图片拉伸
图片拉伸
+(UIImage*)wlisWithImage:(NSString *)name{
//获取图片
UIImage * img=[UIImage imageNamed:name];
//获取图片宽
CGFloat imgW=img.size.width;
//获取图片高
CGFloat imgH=img.size.height;
//获取可拉伸的图片
return [img resizableImageWithCapInsets:UIEdgeInsetsMake(imgH*0.5, imgW*0.5, imgH*0.5, imgW*0.5) resizingMode:UIImageResizingModeTile];
}
/**
以前的拉伸图片
*/
+(UIImage *)stretchableImage:(NSString *)name{
//获取图片
UIImage * img=[UIImage imageNamed:name];
//获取图片宽
CGFloat imgW=img.size.width;
//获取图片高
CGFloat imgH=img.size.height;
/**
leftCapWidth = width - leftCapWidth - 1
topCapHeight = height - topCapWidth - 1
*/
return [img stretchableImageWithLeftCapWidth:imgW*0.5 topCapHeight:imgH*0.5];
}