【问题标题】:Irregular shaped buttons using OBShapedButton with hidden image使用带有隐藏图像的 OBShapedButton 的不规则形状按钮
【发布时间】:2012-10-07 14:58:10
【问题描述】:
我正在尝试使用 OBShapedButton 类制作一个不规则形状的按钮。没关系,创建它没有任何问题,但是我需要图像是透明的。所以,我只想要图像中可以点击的区域,但看不到图像。
我尝试在 image、imageView 和按钮本身上设置 alphas,但是这两种方法都不起作用。
我该怎么做?
也许它可以通过其他东西来完成,而不是 UIButton,但不幸的是我在网上没有找到任何我可以理解和使用的东西。
【问题讨论】:
标签:
objective-c
ios
xcode
uibutton
transparency
【解决方案1】:
好的,所以最简单的方法是:
- 子类 UIButton 并添加 touchesBegan、touchesEnded、touchesMoved、
touchesCancelled。
- 然后在 touchesBegan 上隐藏按钮的图像并在背景中显示正确的图像。
- 最后在 touchesEnded 或 touchesMoved 上,再次显示按钮的图像。
希望对某人有所帮助:)