Ios – changing corner radius of uitableview grouped in iOS6


I've tried using the following code but with no luck. Anybody know how to do this in iOS 6? I do not want to create a custom cell.

self.tableView.layer.cornerRadius = 5.0f;
    [self.tableView setClipsToBounds:YES];


It appears that what's actually happening is that this code is creating a corner radius for the entire view, not each individual UITableViewSection. Does this make sense?

I have also tried [cell.layer setCornerRadius:3.0]; but also with no luck. The corners of my UITableView are still exactly the same.

enter image description here

Best Solution

You can change de backgroundView of the TableViewCell, create a subclass of UIView and change the layer class:

@interface BackgroundView : UIView

@implementation BackgroundView

+ (Class)layerClass
    return [CAShapeLayer class];

later in cellForRowAtIndexPath you do something like this:

static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];

CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer  *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;

return cell;

Results this:

enter image description here

You can modify the corners you want or create another path.

I hope it helps.

Related Question