我需要制作一些相互重叠的三角形按钮。
虽然 UIButtons 可以采用透明图像作为背景,而 UIControls 可以有自定义 View ,但它们的点击区域总是方形的。如何为我的按钮创建一个三角形的点击区域?
我来自 FLash 背景,所以我通常会为我的 View 创建一个 hitarea,但我不相信我可以在 Cocoa 中做到这一点。
有什么建议吗?
最佳答案
您可以通过继承 UIButton
并提供您自己的子类来实现:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
// return YES if point is inside the receiver’s bounds; otherwise, NO.
}
Apple's UIView Documentation提供详细信息,例如确认 point
已经在接收器的坐标系中。
关于cocoa-touch - iOS:按钮的非方形点击区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5649097/