在 iOS 6.0 中,UIView 的 contentStretch 属性已被弃用。 如何使用新/旧/其他 API 实现相同的功能?
我正在寻找的功能是在 UIButton 上拉伸(stretch)图像的一部分(除边缘外的所有内容)。
最佳答案
使用 resizableImageWithCapInsets 和 UIEdgeInsets 制作拉伸(stretch)的 UIButton 背景图像。例如:
UIImage* image = [UIImage imageNamed:@"image.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[button setBackgroundImage:image forState:UIControlStateHighlighted];
我认为水平和垂直拉伸(stretch)不能超过一个像素。
希望这对您有所帮助。
关于ios - 替换 UIView 的 contentStretch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15663721/