iphone - 如何在不挤压背景图像的情况下扩展 UIButton 的 hitTest 区域?

标签 iphone objective-c ios uibutton

我已经设置了 UIButton 的背景图片并在上面放了一个标题(我使用的是 setBackgroundImage 方法而不是 setImage)。现在我想扩展 UIButton 的 hitTest 区域而不挤压它的背景图像。

我该怎么做?

最佳答案

更简洁的方法是覆盖 pointInside。

这是一个 Swift 版本:

override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
    let expandedBounds = CGRectInset(self.bounds, -15, -15)
    return CGRectContainsPoint(expandedBounds, point)
}

关于iphone - 如何在不挤压背景图像的情况下扩展 UIButton 的 hitTest 区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12297467/

相关文章:

ios - 踩在 block 处理程序的 "EXC_BAD_ACCESS KERN_INVALID_ADDRESS"上

iPhone - 向 UITableView 添加新的部分和行

objective-c - 自动旋转 iOS 8 导航 Controller

iphone - 异步下载对象属性

ios - 如何在 objective-c 的 actionSheet 上自动选择一个选项?

ios - 我的应用程序无法在后台运行

iphone - 为什么我们只使用 aurioTouch 项目中的第一个缓冲区

iPhone开发-从用户位置定位地址

iphone - 申报属性(property)的最佳方式是什么?

ios - 当应用程序进入前台时,是否需要重新创建MTLBuffer,MTLTexture或其他 Metal 资源?