I am trying to set the corner radius of a UIView using UIBezierPath. I created the following extension for this:
extension UIView
{
func roundedView(usingCorners corners: UIRectCorner, cornerRadii: CGSize)
{
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: cornerRadii)
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
self.layer.mask = maskLayer
}
}
cvTutorialContainerView.roundedView(usingCorners: [.topRight, .bottomRight, .topLeft, .bottomLeft],
cornerRadii: CGSize(width: 8, height: 8))
The function is being called from viewDidLayoutSubviews()
:
cvTutorialContainerView.roundedView(usingCorners: [.topRight, .bottomRight, .topLeft, .bottomLeft],
cornerRadii: CGSize(width: 8, height: 8))
The problem is I only get a radius for the top corners, for some reasons but only on some occasions, like when using a UIPageView or an UIScrollView.
I tried cvTutorialContainerView.layer.cornerRadius = 8.0
but it didn't work. I also tried calling the function from viewDidLoad and viewDidAppear but again, no luck.
Any ideas?