objective-c - resizableImageWithCapInsets : resizingMode: UIImageResizingModeTile isn't working

标签 objective-c image-resizing

UIImage 的 resizableImageWithCapInsets 方法非常适合带圆角的标准矩形按钮,但我正在尝试创建一个看起来像云的按钮,边缘不均匀。我不太清楚绘制或创建它的最佳方式,或者当我将它放入我的应用程序时我将如何扩展它。我在谈论这样的事情:

enter image description here

云朵两侧的气泡不应拉伸(stretch),但无论按钮需要多长/多短,都会创建新的气泡。例如,如果按钮需要是此图像大小的一半,则只会显示 2 个气泡,但如果需要更高,可能超过此处的 5 个,它会根据需要添加和删除它们.我会设置最小尺寸,以便至少有一个气泡始终存在,以防止在它变得太小时出现问题。如果需要,可以平铺气泡本身。

有没有人从软件开发或图形设计的角度对我如何实现这样的效果有什么建议?

编辑:

我已尝试使用下图和以下代码执行此操作,它给出的结果与此处的图像类似。图像的尺寸甚至都不合适,更不用说平铺了。我已经确认图像的框架也比此处显示的要大。这里真的很困惑!

cappedCloud = [[UIImage imageNamed: @"cloud.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(9, 9, 9, 9) resizingMode: UIImageResizingModeTile];

[[cell.cloudButton imageView] setContentMode: UIViewContentModeScaleToFill];
[cell.cloudButton setImage: cappedCloud forState: UIControlStateNormal];
[cell.cloudButton setAlpha: 0.85f];

enter image description here

enter image description here

最佳答案

您可能想研究如何创建 tiled resizable image使用

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode

使用稍微修改过的代码版本,我能够让图像平铺在按钮上,尽管它平铺得不是很好:

UIImage* cappedCloud = [[UIImage imageNamed: @"cloud.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(9, 9, 9, 9) resizingMode: UIImageResizingModeTile];

[cloudButton setBackgroundImage:cappedCloud forState:UIControlStateNormal];
[cloudButton setAlpha: 0.85f];

cloudImage.image = cappedCloud;

enter image description here

关于objective-c - resizableImageWithCapInsets : resizingMode: UIImageResizingModeTile isn't working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15250576/

相关文章:

javascript - 在 Windows 应用商店应用程序中调整图像大小

javascript - 调整页面大小时调整图像大小

ImageMagick 按百分比和限制调整大小

iphone - ios 调整拇指的图像大小 - 虽然高插值但模糊

css - 响应式 2 张图像超过另一张图像问题

ios - 为 iOS 设计矩形按钮的指南

objective-c - 使用另一个 Swift 文件从 Objective C 类获取 Swift 对象

objective-c - 一段时间后菜单栏菜单项将被禁用

ios - Objective-C/C。当我尝试在 IOS 设备上获取 Mac 地址时,我得到了错误的值

objective-c - 如何使我的图像可点击