在ios 7中的UITableView部分周围绘制边界线

时间:2014-04-07 11:18:35

标签: ios objective-c xcode5

我对部分边框有疑问。我有一个UITableView,它的类型为Grouped。我试图在tableview的每个部分周围绘制边框。我使用下面的代码获取部分框架。请告诉我如何在UITableView部分绘制边框。

CGRect rect = [groupsTableView rectForSection:indexPath.section];

NSLog(@"%f %f %f %f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);

enter image description here

1 个答案:

答案 0 :(得分:0)

我建议你制作一个新的TableView Cell并在这个newTableViewCell中加载第2节中的所有单元格,然后为newTableViewCell提供边框。

但如果您不想这样做,那么您可以使用此代码:

@property(strong,nonatomic) CAShapeLayer* borderPath;

-(void)viewDidLayoutSubviews{
[_borderPath removeFromSuperlayer];
UIView *viewToGiveBorder = [[UIView alloc]initWithFrame:sectionView.frame];

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:viewToGiveBorder.bounds byRoundingCorners:(UIRectCornerAllCorners) cornerRadii:CGSizeMake(5.0, 5.0)];

//apply path to shapelayer
_borderPath= [CAShapeLayer layer];
_borderPath.path = path.CGPath;
[_borderPath setFillColor:[UIColor clearColor].CGColor];
[_borderPath setStrokeColor:[UIColor colorWithRed: 0 green: 0 blue: 0].CGColor];
_borderPath.frame=sectionView.frame;

//add shape layer to view's layer
[[self.view layer] addSublayer:_borderPath];
}