gpt4 book ai didi

ios - 带有圆角的 UIButton 的事件可点击区域?

转载 作者:搜寻专家 更新时间:2023-10-31 22:32:00 25 4
gpt4 key购买 nike

所以我在 Storyboard中创建了一个带边框的按钮。 enter image description here

然后我将它的角弄圆并添加了边框颜色:

button.layer.cornerRadius = button.bounds.size.width / 2
button.layer.borderColor = greenColor

因此运行结果如下所示: enter image description here

但是,用户可以在按钮区域之外(以前是角所在的位置)轻轻点击,仍然可以调用按钮功能。有没有办法将按钮的启用区域限制为圆圈?

最佳答案

对于其他答案,您会阻止触摸,我需要它才能通过。而且更容易:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com