【发布时间】:2016-10-21 06:27:40
【问题描述】:
我想为我的 UI 元素设置圆角半径,如附加快照所示:
我尝试使用UIBezierPath 设置拐角半径,但它没有给出预期的结果。我还在UIView 中添加了这三个UIButtons,并将角半径设置为容器视图但没有用。
参考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
以下是我得到的输出:
任何帮助表示赞赏。谢谢
【问题讨论】:
-
是否有 2 个 uiview 用于一个取消,一个用于 3 个选项?
-
没有。取消按钮不在容器视图中。取消按钮角半径工作正常,因为 cancelButton.layer.cornerRadius = 15
-
扫描按钮看起来与我期望它给出的面具完全一样。有什么理由不只是将 UIAlertController 与操作表样式一起使用?
-
UIAlertController 将从底部弹出并粘在 UIView 的底部。我希望它位于屏幕中心
标签: ios uiview uibutton swift3 cornerradius