美文网首页
给整个tableView界面画圆弧

给整个tableView界面画圆弧

作者: 夜空已沉寂 | 来源:发表于2016-10-15 10:18 被阅读116次

这个是给整个tableView画圆弧 让整个界面美观,可以把这个代码全部复制进入你创建的tableView界面,然后修改下几个参数就可以了,(那点错误修改那里用你自己项目中的替代这个就可以了)

/**

*  圆弧

*

*  @param tableView <#tableView description#>

*  @param cell      <#cell description#>

*  @param indexPath <#indexPath description#>

*/

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

if ([cell respondsToSelector:@selector(tintColor)]) {

if (tableView == self.myTableView) {//这里只需要让你的tableView等于自己创建的tableView就行了

CGFloat cornerRadius = 0.f;

cell.backgroundColor = UIColor.clearColor;

CAShapeLayer *layer = [[CAShapeLayer alloc] init];

CGMutablePathRef pathRef = CGPathCreateMutable();

CGRect bounds = CGRectInset(cell.bounds, 0, 0);

BOOL addLine = NO;

if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {

CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);

} else if (indexPath.row == 0) {

CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));

CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);

CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);

CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));

addLine = YES;

} else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {

CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));

CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);

CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);

CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));

} else {

CGPathAddRect(pathRef, nil, bounds);

addLine = YES;

}

layer.path = pathRef;

CFRelease(pathRef);

layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;

if (addLine == YES) {

if(indexPath.row == 0){

CALayer *lineLayer = [[CALayer alloc] init];

CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);

lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);

lineLayer.backgroundColor = [YBBColor colorTableHeaderSeparatorColor].CGColor;

[layer addSublayer:lineLayer];

}else{

CALayer *lineLayer = [[CALayer alloc] init];

CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);

lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);

lineLayer.backgroundColor = [YBBColor colorTableSeparatorColor].CGColor;

[layer addSublayer:lineLayer];

}

}

UIView *testView = [[UIView alloc] initWithFrame:bounds];

[testView.layer insertSublayer:layer atIndex:0];

testView.backgroundColor = UIColor.clearColor;

cell.backgroundView = testView;

}

}

}

相关文章

网友评论

      本文标题:给整个tableView界面画圆弧

      本文链接:https://www.haomeiwen.com/subject/qpinyttx.html