![971366-86e03ea2928db71f.png](https://i-blog.csdnimg.cn/blog_migrate/3210bcfd97a7c04f6a15d36f023f8429.png)
![971366-5f65e64daea70fbb.png](https://i-blog.csdnimg.cn/blog_migrate/fd322795db5d56bbcbbe4c1baa2dbf4f.png)
//如果是UIImageView,可以在xib中设置Stretching属性,x,y设为0.5,width,height设为0,就可以拉伸图片,解决图片过小而产生四周模糊的效果,如果是UIbutton,只能通过代码实现
//先把image拉伸后在赋给UIButton,拉伸图片有两个方法
UIImage *image = [UIImage imageNamed:@"RedButton"];
[_butt setBackgroundImage:image forState:UIControlStateNormal];
//1.这种方式只需要两个参数,以中心点向左,向上1px向外拉伸
image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
//这种方法需要四个参数,一般用第一种就可以
//image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.5, image.size.width * 0.5, image.size.height * 0.5, image.size.width * 0.5 )];
[_butt2 setBackgroundImage:image forState:UIControlStateNormal];