ios中达到Android中九妹图的效果不需要另外用工具对图片进行转换,直接使用UIImage的
stretchableImageWithLeftCapWidth:(NSInteger) topCapHeight:(NSInteger) 函数就能做到,可拉伸的范围都是距离leftCapWidth后的1竖排像素,和距离topCapHeight后的1横排像素。
例子:Button 需要根据title的长度调整frame时,Button的背景图片也会跟着调整,这时候如果背景图片是圆角的,我们不想看到圆角的弧度改变,就设置leftCapWidth为图片左边弧度占的像素个数:
[buttonsetBackgroundImage:[[UIImageimageNamed:@"图片.png"]stretchableImageWithLeftCapWidth:20 topCapHeight:2]forState:UIControlStateSelected];