ios - 替换 UIView 的 contentStretch?

标签 ios uiview ios6 deprecated stretching

在 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/

相关文章:

ios - 界面生成器中 UIView 的边框颜色不起作用?

ios - 如何在图片上写文字并保存

ios - 在 iOS 6 中无法使用相机扫描 PDF 417 条码

ios - 用于 Cordova 2.0 的 Phonegap IOS PrintPlugin

iphone - 如何使用 Interface Builder 正确控制 UINavigationControllers?

ios - 将 iOS PT 转换为 Android DP?

iOS 从 RSS Feed 获取日期字符串

uitableview - ios6、UITableViewCell背景

ios - 将应用上传到 App Store 后,Firebase 号码身份验证不起作用

ios - 在 Collection View 中为 UImageView 添加标题标签