【发布时间】:2023-03-06 14:34:01
【问题描述】:
我在 UIView 中添加了圆角功能扩展
它在 iPhone XR 等新设备上完美运行,但在 iPhone 8,iPhone 8 plus 等比例为 16:9 的旧设备上它在左侧拐角
extension UIView{
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
当我实现该功能时。在UIViewController里面,我调用viewDidLayoutSubviews里面的函数@
//ViewController
override func viewDidLayoutSubviews() {
exampleView.roundCorners([.topRight,.topLeft], radius: 20)
}
- 但是当我在课堂上用另一种类型实现时,我找不到解决方案, 我想要一种方法来强制占据角落。
【问题讨论】:
标签: ios swift xcode rounded-corners