Ale*_*les 33
一种常见的技术是使用图像作为背景.实际上你可以使用一个可伸缩的图像:
- (void)viewDidLoad {
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}
Run Code Online (Sandbox Code Playgroud)
原始图片:
最终结果:
我发现这篇文章解释了如何在没有图像和完全代码的情况下完成此操作.
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
希望有所帮助.