UITableView中的圆顶角

时间:2013-07-03 15:31:01

标签: objective-c ios4 uitableview iphone-sdk-3.0

我确实在UItableView中添加了圆角但仅在顶角。 问题是当我在UItableView中使用mask时,UItableView只显示前4个单元格。

当我评论掩码中的代码时,tableview工作正常..

这是我的代码:

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 个答案:

答案 0 :(得分:0)

执行此操作的方法是在表格视图中添加标题:

- (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;
}