Ray Smith
Ray Smith

Reputation: 73

CornerRadius don't set

I'm trying to round the corners on the UIView in bottom left and bottom right. enter image description hereenter image description here

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
    }
}

And call cell.bottomCorner.roundBottom(8)

But I get it:

iPhone 5:

enter image description here

iPhone 6s:

enter image description here

iPhone 6s Plus:

enter image description here

Upvotes: 1

Views: 93

Answers (1)

Sulthan
Sulthan

Reputation: 130102

You have to update the mask everytime the view changes its size, therefore ideally you should change it whenever UIView.layoutSubviews is called:

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

It's not ideal to do it in an extension helper method. You should create a specific class to handle the size change.

Upvotes: 3

Related Questions