我对部分边框有疑问。我有一个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);
答案 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];
}