替换UIView的内容Strestch?

时间:2013-03-27 16:12:53

标签: ios uiview ios6 deprecated stretching

在iOS 6.0中,不推荐使用UIView的contentStretch属性。 如何使用new / old / other API实现相同的功能?

我正在寻找的功能只是在UIButton上拉伸图像的一部分(除了边缘之外的所有内容)。

1 个答案:

答案 0 :(得分:5)

使用resizableImageWithCapInsets和UIEdgeInsets来制作拉伸UIButton背景图像。例如:

UIImage* image = [UIImage imageNamed:@"image.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[button setBackgroundImage:image forState:UIControlStateHighlighted];

我认为你不能在水平和垂直方向上拉伸多个像素。

希望这有帮助。