廢話不多說旭绒,直接上代碼 --
//保護左右側,中間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;
}