Dru*_*erB 70
从您提供的示例图像中我很确定您正在寻找UIImage的resizableImageWithCapInsets:
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
UIImage *stretchableImage = [originalImage resizableImageWithCapInsets:insets];
[myButton setBackgroundImage:stretchableImage forState:UIControlStateNormal];
// the image will be stretched to fill the button, if you resize it.
Run Code Online (Sandbox Code Playgroud)
UIEdgeInsets结构中的值确定您不希望拉伸的边距.你的左右值可以是这么宽:

顶部和底部值可以是0(如果您不想垂直调整按钮的大小),或者可能是总高度的一半.
| 归档时间: |
|
| 查看次数: |
35819 次 |
| 最近记录: |