2011-10-31 117 views
2

我制作了自定义的uiTableViewCell并使用它像屏幕截图一样使用了UITableview。 问题是组表上的第一个和最后一个单元的圆角。 enter image description hereUITableViewCell组合表的第一个和最后一个单元格的圆角

如何使拳头和最后一个单元格圆角

+0

[如何自定义分组表视图的背景/边框颜色?](http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of -a-grouped-table-view) – rckoenes

+0

请在发布查询之前彻底搜索StackOverflow。有这么多的问题。 – Legolas

+0

我已阅读它,但我不解决它从我的问题发生从UITableViewCell和组表。 – dobiho

回答

0

关键是要设置

view.layer.cornerRadius = 10; 

看看这个示例项目上this link!

+2

这回合视图的所有角落,而只有一个必须被舍入 –

0

尝试设置单元格的背景颜色clearColor:您的表格似乎有圆角,但您的单元格正在覆盖它。另一种替代解决方案可能是更改表格背后的视图属性。尝试:

backgroundView.clipsToBounds = YES; 

tableView.layer.cornerRadius = 5; 
tableView.layer.masksToBounds = YES; 

您可能需要

#import <QuartzCore/QuartzCore.h> 
3

添加的tableView的财产你的,并设置它在你的控制器:

@property (nonatomic, weak) UITableView *tableView; 

然后你可以像这样实现它:

- (void)layoutSubviews { 
    [super layoutSubviews]; 

    UIRectCorner rectCorner; 
    BOOL roundCorners = YES; 
    NSIndexPath *indexPath = [self.tableView indexPathForCell:self]; 
    NSInteger numberOfRows = [self.tableView numberOfRowsInSection:indexPath.section]; 

    if (numberOfRows == 1) { // single cell 
     rectCorner = UIRectCornerAllCorners; 
    } else if (indexPath.row == numberOfRows - 1) { // bottom cell 
     rectCorner = UIRectCornerBottomLeft | UIRectCornerBottomRight; 
    } if (indexPath.row == 0) { // top cell 
     rectCorner = UIRectCornerTopLeft | UIRectCornerTopRight; 
    } else { 
     roundCorners = NO; 
    } 

    if (roundCorners) { 

     CGFloat cornerRadius = 10.0; 
     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds 
                 byRoundingCorners:rectCorner 
                  cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; 
     CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
     maskLayer.frame = self.bounds; 
     maskLayer.path = maskPath.CGPath; 
     self.layer.mask = maskLayer; 
    } 
} 

您可避免通过检查self.superview.superview(iOS7,self.superview之前),其上的属性tableView,但我认为这是一个更清洁,不易出错的方式。

相关问题