简体   繁体   English

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

[英]draw borderline around UITableView section in ios 7

I have an issue regarding the section border. 我对截面边框有疑问。 I have a UITableView and it is of type Grouped. 我有一个UITableView ,它的类型为Grouped。 I am trying to draw the border around the each section of the tableview. 我正在尝试在tableview的每个部分周围绘制边框。 I am getting the section frame using the below code. 我正在使用以下代码获取截面框架。 Could please tell me how to draw the border around the UITableView section. 请告诉我如何在UITableView部分周围绘制边框。

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

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

在此处输入图片说明

I will recommend that you make a new TableView Cell and inside this newTableViewCell, load all the cells in section 2 then give border to newTableViewCell. 我建议您创建一个新的TableView Cell,并在此newTableViewCell内,加载第2部分中的所有单元,然后为newTableViewCell提供边框。

but if you don't wanna do that then you can use this code : 但是,如果您不想这样做,则可以使用以下代码:

@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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM