BObereder
BObereder

Reputation: 1046

Access corner radius of UITableViewCell in grouped TableView

It seems Apple changed the corner radius in iOS6 to about 7 (previously 10).

I have a view behind my UITableView that needs to have the same corner radius then the UITableViewCell. My app sopports also previous iOS Versions so I have to adapt the corner radius of my view to the one which the current UITableview has. Is there a way to access the corner radius of the cell?

Upvotes: 2

Views: 564

Answers (1)

Vizllx
Vizllx

Reputation: 9246

@bllubbor - You Can go by this method, Hope it solved your Answer as it works for me..

@interface BackgroundView : UIView
    @end

    @implementation BackgroundView

    + (Class)layerClass
    {
        return [CAShapeLayer class];
    }
    @end

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;

Upvotes: 1

Related Questions