Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBezierPath does not draw rounded bottom corners

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!

like image 793
Mert Avatar asked Apr 23 '13 09:04

Mert


2 Answers

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.

like image 86
Oly Dungey Avatar answered Oct 23 '22 09:10

Oly Dungey


I think you should use

bezierPath.lineCapStyle = CGLineCap.Round
like image 35
wkwyatt Avatar answered Oct 23 '22 10:10

wkwyatt