1 1. 2 // 1.创建个图片对象 3 UIImage *image = [UIImage imageNamed:@"buttongreen"]; 4 5 // 2.根据图片创建一个可以拉伸的图片 6 image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; 7 8 [self.btn setBackgroundImage:image forState:UIControlStateNormal]; 9 10 2. 11 12 // 1.创建个图片对象 13 UIImage *image = [UIImage imageNamed:@"chat"]; 14 15 // 2.获得可拉伸的区域 16 CGFloat imageW = image.size.width; 17 CGFloat imageH = image.size.height; 18 // 3.根据图片创建一个可以拉伸的图片 19 image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(imageH * 0.5, imageW * 0.5, imageH * 0.5, imageW * 0.5) resizingMode:UIImageResizingModeTile]; 20 [self.btn setBackgroundImage:image forState:UIControlStateNormal];