图像小于可触摸区域的 UI 按钮
我没有太多回应,所以添加一些更多信息。
我的按钮不是矩形的,也不是按网格组织的,因此我需要一种创建看起来像按钮的方法(并显示它已被视觉按下,按照标准 UIButton),但可触摸区域与图像区域不同。
我使用的是透明 PNG,该元素工作正常。我已在 Interface Builder 中添加了按钮,我想知道这是否是问题所在。
但是,如果我更改 imageEdgeInsets,它会扭曲图像显示,这显然不是我想要的。
奇怪的是,如果我增加按钮的尺寸,它不会改变图像,但如果我减小它们,它就会改变图像。
我尝试了不同的模式组合(缩放填充等),但无济于事。
我知道有图像和背景图像属性,但在 IB 中只有一个。
本质上,我不明白几何是如何工作的,苹果文档似乎也没有帮助。
当然,我不是唯一一个尝试这样做的人。任何帮助都将受到热烈欢迎。
非常感谢,
克里斯。
I've not much response so am adding some more info.
My buttons are not rectangular, nor organised in a grid so I need a way of creating what looks like a button (and shows that it has been pressed visually, as per a standard UIButton) but where the touchable area is different to the image area.
I am using a transparent PNG and that element works fine. I've added the buttons in Interface Builder and am wondering if that is the problem.
However, if I change imageEdgeInsets, it distorts the image display, which is obviously not what I want.
Bizarrely, if I increase the dimemsions of the button, it doesn't change the image, but if I decrease them it does.
I have tried different combinations of mode (scale to fill etc), but to no avail.
I am aware that there is an image and background image property, but in IB there is only one.
Essentially, I don't understand how the geometry works and the Apple documentation doesn't seem to help.
Surely, I can't be the only person to try to do this. Any help would be warmly welcomed.
Many thanks,
Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将按钮设置设置为 Aspect Fit。这将用您的图像填充按钮,因此比按钮尺寸更小的图像将在图像周围留下空间。
还将按钮类型设置为自定义。
Try setting the buttons setting to Aspect Fit. This will fill the button with your image so a smaller image than the button size would leave the space around the image.
Also set the button type to custom.
最后,我偶然发现了 Ole Begemann 的 Non -矩形按钮类。它只是满足我的需要 - 能够创建按钮,其中可触摸区域遵循非矩形图像的可见元素。
@Helium3 - 谢谢 - 这让我可以使用更大的触摸区域,而不是更小的触摸区域。
In the end, I stumbled across Ole Begemann's Non-rectangular buttons class. It just does what I need - to be able to create buttons where the touchable area follows the visible element of a non rectangular image.
@Helium3 - thanks - that allowed me to use a larger touch area, bit not a smaller one.