UIBezierPath does not draw rounded bottom corners

Mert picture Mert · Apr 23, 2013 · Viewed 8.9k times · Source

I am trying to make rounded corners for my views and fencing a strange problem.

I use the following code to make rounded corners for my view

bezierPath = [UIBezierPath bezierPathWithRoundedRect:btnView.bounds
                                       byRoundingCorners:UIRectCornerAllCorners
                                             cornerRadii:radius];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = btnView.bounds;
    maskLayer.path = bezierPath.CGPath;
    btnView.layer.mask = maskLayer;

The problem is, it is not working for bottom corners. If I use UIRectCornerBottomLeft nothing happens, if I use UIRectCornerAllCorners only top corners are rounded.

EDIT: I dont use layer.cornerRadius because I just want to round bottom corners.

It turned out I do not have problem, if I remove UIViewAutoresizingFlexibleHeight autoresizing mask from my view. But I would like to use autoresizing mask. Is it possible if yes how?

I have already tried setting autoresizingMask before and after setting the mask of the layer. No luck!

Answer

Oliver Dungey picture Oliver Dungey · Jun 25, 2014

I have just had a similar problem that's taken hours to solve - the answer was very simple: move my code from viewDidLoad to viewDidLayoutSubviews: this is the first method called after autolayout has completed .... so I suspect I did have 4 rounded corners but somehow they were off the edge of the screen.