5

在 iOS 6.0 中 UIView 的 contentStretch 属性已被弃用。如何使用新/旧/其他 API 实现相同的功能?

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

4

1 回答 1

5

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

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

我认为您不能在水平和垂直方向上拉伸超过一个像素。

希望这可以帮助。

于 2013-03-27T19:16:19.120 回答