废话不多说,直接上代码 --
//保护左右侧,中间1像素进行mode
UIImage * imageProtectLeftRight(UIImage *image, UIImageResizingMode mode)
{
CGFloat top = 0;
CGFloat bottom = 0;
CGFloat left = image.size.width*0.5-1;
CGFloat right = image.size.width*0.5-1;
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
UIImage *img = [image resizableImageWithCapInsets:insets resizingMode:mode];
return img;
}
//保护上下侧,中间1像素进行mode
UIImage * imageProtectTopBottom(UIImage *image, UIImageResizingMode mode)
{
CGFloat top = image.size.height*0.5-1;
CGFloat bottom = image.size.height*0.5-1;
CGFloat left = 0;
CGFloat right = 0;
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
UIImage *img = [image resizableImageWithCapInsets:insets resizingMode:mode];
return img;
}
//保护上下左右侧,中间1像素进行mode
UIImage * imageProtect(UIImage *image, UIImageResizingMode mode)
{
CGFloat top = image.size.height*0.5-0.5;
CGFloat bottom = image.size.height*0.5-0.5;
CGFloat left = image.size.width*0.5-0.5;
CGFloat right = image.size.width*0.5-0.5;
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
UIImage *img = [image resizableImageWithCapInsets:insets resizingMode:mode];
return img;
}