然后我将它的角弄圆并添加了边框颜色:
button.layer.cornerRadius = button.bounds.size.width / 2
button.layer.borderColor = greenColor
但是,用户可以在按钮区域之外(以前是角所在的位置)轻轻点击,仍然可以调用按钮功能。有没有办法将按钮的启用区域限制为圆圈?
最佳答案
对于其他答案,您会阻止触摸,我需要它才能通过。 而且更容易:
1) 设置你喜欢的路径(我圈)
private var touchPath: UIBezierPath {return UIBezierPath(ovalIn: self.bounds)}
2) 在函数内覆盖点
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return touchPath.contains(point)
}
所有在你的 UIButton 子类中。
关于ios - 带有圆角的 UIButton 的事件可点击区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617784/