我已经设置了 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/