Round top corners in UITableView

674 Views Asked by At

I did add round corner in UItableView but only in top corners. The problem is that when I use mask in UItableView, the UItableView show only the first 4 cells.

When I comment the code from mask, the tableview works fine..

Here is my code:

UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:_tbFeeds.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(9.0, 9.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _tbFeeds.bounds;
maskLayer.path = maskPath.CGPath;
_tbFeeds.layer.mask = maskLayer; //tbfeeds is my tableview
[maskLayer release];
1

There are 1 best solutions below

0
Maschel On

A way to do this would be to add a header to the tableview:

- (void)loadView {
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)]; // height of header (10)
    [headerView setBackgroundColor:[UIColor whiteColor]]; // color of header (white)

    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:headerView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(5.0, 5.0)];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = headerView.bounds;
    maskLayer.path = maskPath.CGPath;
    headerView.layer.mask = maskLayer;

    self.tableView.tableHeaderView = headerView;
}