iOS装置:用于按钮非正方形灾区 [英] iOS: Non-square hit areas for buttons

查看:97
本文介绍了iOS装置:用于按钮非正方形灾区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要互相重叠的一些三角形的按钮。

I need to make some triangular buttons that overlap each other.

虽然UIButtons可以采取透明的图像作为背景,UIControls可以自定义视图,这些点击区域始终是方形。我如何能为我的按钮创建一个三角形hitarea?

While UIButtons can take transparent images as backgrounds, and UIControls can have custom views, the hit area of these is always square. How can I create a triangular hitarea for my buttons?

我来自一个闪光的背景,所以我通常会创造我认为一个hitarea,但我不相信我可以在可可做到这一点。

I come from a FLash background so I would normally create a hitarea for my view, but I don't believe I can do this in Cocoa.

任何提示?

推荐答案

您可以通过继承的UIButton 并提供实现这一主题:

You can achieve this by subclassing UIButton and providing your own:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    // return YES if point is inside the receiver’s bounds; otherwise, NO.
}

<一个href=\"http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html\"相对=nofollow>苹果的UIView的文档提供了详细信息,如确认已经接收器的坐标系中

Apple's UIView Documentation provides the details, such as confirming that point is already in the receiver's coordinate system.

这篇关于iOS装置:用于按钮非正方形灾区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆