Reputation: 20058
I extended UIView
to add a round() method to apply corner radius to specific corners:
extension UIView {
func round(corners: UIRectCorner, radius: CGFloat) -> CAShapeLayer {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
return mask
}
}
In one view controller I have the following hierarchy:
Constraint are set to both for top, leading, trailing as 0.
My issue is when I run (only) 5.5 inch screen, the UIView is not stretched all the way as it should be when I apply the corner radius to it:
override func viewDidLayoutSubviews() {
self.greenview.round([.TopLeft, .TopRight], radius: CGFloat(10))
}
If I remove this line it works correctly. Am I not calling this method in the right place ?
Here is a screen shot of the problem:
Upvotes: 3
Views: 942
Reputation: 585
Try putting it in 'layoutSubviews' after calling the super method. It's more appropriate for bounds-dependent UI changes.
Upvotes: 4