在UIButton中加入一个UIImageView,拉伸imageView的UIimage,然后将button的背景设为clearColor等等。把imageView放入button中,
//刚才image拉伸的代码
//图片处理
CGFloat top = floorf(image.size.height/2); // 顶端盖高度
CGFloat bottom = image.size.height-(image.topCapHeight+1) ; // 底端盖高度
CGFloat left = floorf(image.size.width/2); // 左端盖宽度
CGFloat right = image.size.width - (image.leftCapWidth + 1); // 右端盖宽度
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
// 指定为拉伸模式,伸缩后重新赋值
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
这是本人试出来的方法,也是唯一适合Button的方法,如果有更好的,欢迎大家提供下