【问题标题】:How to use resizableImageWithCapInsets on UIImage?如何在 UIImage 上使用 resizableImageWithCapInsets?
【发布时间】:2013-08-30 11:02:53
【问题描述】:

我想拍一张这样的照片:

我写了代码:

[[[UIImage imageNamed:@"background.png"] 
  resizableImageWithCapInsets:UIEdgeInsetsMake(1.f, 1.f, 1.f, 1.f)]
  drawInRect:rect];

但我使用这段代码:

为什么???如何在四边固定 1px 的矩形中绘制调整大小的图像?

【问题讨论】:

  • 查看this answer了解如何使用它
  • 该图像的边缘是什么?边框上有透明像素吗?
  • 我应该使用拉伸模式吗?并且默认使用 Titled。
  • 没有透明像素。我想修复 1px 并调整所有其他内容的大小。
  • 大卫,感谢您的帮助!

标签: iphone ios uiimage


【解决方案1】:

在 iOS 6+ 上使用以下代码拉伸图像:

[[[UIImage imageNamed:@"background.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1.f, 1.f, 1.f, 1.f) resizingMode:UIImageResizingModeStretch]drawInRect:rect];

【讨论】:

  • 这不是正确的答案。这将在不考虑指定的边缘插图的情况下拉伸图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多