Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round only corners on a UITableView?

I am trying to round only the top right and left corners of my tableview. I am using the code below and it only seems to be rounding the top left corner...

CAShapeLayer *topLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = 
[UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(9.f, 9.0f)];    
topLayer.path = [roundedPath CGPath];
like image 666
Luke Avatar asked Nov 03 '22 22:11

Luke


1 Answers

Hope this will work. Find the top corner paths to create a mask layer

UIBezierPath *PathToMask;
PathToMask = [UIBezierPath bezierPathWithRoundedRect:self.testView.bounds
                                 byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                       cornerRadii:CGSizeMake(8.0, 8.0)];

Create a shape layer mask using the UIBezierPath maskPath

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame =self.testView.bounds;
maskLayer.path = PathToMask.CGPath;

set the mask layer maskLayer

self.testView.layer.mask = maskLayer;
like image 190
neerajPK Avatar answered Nov 08 '22 05:11

neerajPK