5

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];
Abubakr Dar
  • 4,078
  • 4
  • 22
  • 28
Luke
  • 612
  • 1
  • 6
  • 19
  • http://stackoverflow.com/a/5826698/855738 I used this answer to do pretty much the same thing – BBog Jun 12 '12 at 21:19
  • 1
    Know its an old post but just make sure youve got. [tableView.layer setMasksToBound: YES] and it should be fine and dandy – Taylor Abernethy Newman Oct 01 '14 at 19:04
  • See the accepted answer [here][1]. It may be the same issue. [1]: http://stackoverflow.com/questions/26934231/uiview-in-cell-cant-round-right-hand-corners – Murray Sagal Jan 17 '15 at 16:34

1 Answers1

2

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;
neerajPK
  • 293
  • 1
  • 4
  • 17