【问题标题】:CornerRadius don't setCornerRadius 未设置
【发布时间】:2019-04-05 15:04:37
【问题描述】:

我正在尝试在左下角和右下角的 UIView 上圆角。

extension UIView {    
    func roundBottom(raduis: CGFloat){
        let maskPath1 = UIBezierPath(roundedRect: bounds,
                                     byRoundingCorners: [.BottomRight, .BottomLeft],
                                     cornerRadii: CGSize(width: raduis, height: raduis))
        let maskLayer1 = CAShapeLayer()
        maskLayer1.frame = bounds
        maskLayer1.path = maskPath1.CGPath
        layer.mask = maskLayer1
    }
}

并致电cell.bottomCorner.roundBottom(8)

但我明白了:

iPhone 5:

iPhone 6s:

iPhone 6s Plus:

【问题讨论】:

    标签: ios swift uiview swift2


    【解决方案1】:

    您必须在每次视图更改其大小时更新掩码,因此理想情况下您应该在调用UIView.layoutSubviews 时更改它:

    override func layoutSubviews() {
       super.layoutSubviews();
       // update mask
    }
    

    在扩展助手方法中这样做并不理想。您应该创建一个特定的类来处理大小变化。

    【讨论】:

      猜你喜欢
      • 2016-02-28
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 2015-08-15
      • 2011-11-06
      相关资源
      最近更新 更多