仅将圆角半径设置为 UIView/UIButton 的特定一侧

2024-01-09

我想为我的 UI 元素设置圆角半径,如附加的快照所示:

我尝试使用设置角半径UIBezierPath但它没有给出预期的结果。我还添加了这三个UIButtons in UIView并将角半径设置为容器视图但没有用。

参考https://stackoverflow.com/a/31233171/4886069 https://stackoverflow.com/a/31233171/4886069,以下是我在顶部和底部按钮上尝试过的代码:

let rectShape = CAShapeLayer()
rectShape.bounds = self.scanButton.frame
rectShape.position = self.scanButton.center
rectShape.path = UIBezierPath(roundedRect: self.scanButton.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.scanButton.layer.mask = rectShape

let rectShape1 = CAShapeLayer()
rectShape1.bounds = self.manualButton.frame
rectShape1.position = self.manualButton.center
rectShape.path = UIBezierPath(roundedRect: self.manualButton.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.manualButton.layer.mask = rectShape1

以下是我在容器视图上尝试过的代码:

containerView.layer.cornerRadius = 20

以下是我得到的输出:

任何帮助表示赞赏。谢谢


使用topRight、bottomLeft 和bottomRight通过RoundingCorners:[.topLeft]为您的预期结果选择其他角落。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅将圆角半径设置为 UIView/UIButton 的特定一侧 的相关文章

随机推荐