iOS 图片拉伸技巧

第一种:拉伸一张图片的中心位置

UIImage *image = [UIImage imageNamed:@"image"];
image = [image stretchableImageWithLeftCapWidth:floorf(image.size.width/2) topCapHeight:floorf(image.size.height/2)];

第二种:拉伸图片的某个区域(可选拉伸模式)

CGFloat top =25;// 顶端盖高度
CGFloat bottom =25;// 底端盖高度
CGFloat left =10;// 左端盖宽度
CGFloat right =10;// 右端盖宽度

UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
// 指定为拉伸模式(拉伸或者平铺),伸缩后重新赋值
UIImage *image = [UIImage imageNamed:@"image"];
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];

注意:只拉伸左右,要保持图片宽度与图片真实高度一致。

你可能感兴趣的:(iOS 图片拉伸技巧)