增加边框 用颜色事半功倍(方法三)
2017-07-04 本文已影响8人
大虾咪
#pragma mark - =========给cell添加边框 =========
//TODO:方法一
// UIBezierPath *maskPath;
// CGRect boardRect;
//
// float h = cell.bounds.size.height;
// float w = cell.bounds.size.width;
// if (indexPath.row == 0) {
// boardRect = CGRectMake(1, 0, w-1, h);
// maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 10)] bezierPathByReversingPath];
// }
// else if (indexPath.row == 6) {
// boardRect = CGRectMake(-1, 0, w+1, h);
// maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)] bezierPathByReversingPath];
// } else if (indexPath.row == 35) {
// boardRect = CGRectMake(0, -1, w, h+1);
// maskPath = [[UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)] bezierPathByReversingPath];
// }
// else {
// boardRect = CGRectMake(-1, 0, w+2, h);
// maskPath = [UIBezierPath bezierPathWithRect:boardRect];
// }
//
// for (CALayer *layer in cell.contentView.layer.sublayers) {
// if ([layer.name isEqualToString:@"maskLayer"]) {
// [layer removeFromSuperlayer];
// }
// }
//
// CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//
// maskLayer.name = @"maskLayer";
// maskLayer.frame = boardRect;
// maskLayer.path = maskPath.CGPath;
// maskLayer.strokeColor = [UIColor redColor].CGColor;
// maskLayer.lineDashPattern = @[@4, @2];
// maskLayer.lineWidth = 1.0f;
// maskLayer.fillColor = [UIColor clearColor].CGColor;
// maskLayer.masksToBounds = YES;
// [cell.contentView.layer insertSublayer:maskLayer atIndex:0];
//TODO:方法二
// CALayer *bottomBorder = [CALayer layer];
// float height=cell.frame.size.height-1.0f;
// float width=cell.frame.size.width;
// bottomBorder.frame = CGRectMake(0.0f, height, width, 1.0f);
// bottomBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
// [cell.layer addSublayer:bottomBorder];
//
//
// CALayer *rightBorder = [CALayer layer];
// float rightHeight=cell.frame.size.height;
// float rightWidth=cell.frame.size.width-.0f;
// rightBorder.frame = CGRectMake(rightWidth, 0, 1.0f, rightHeight);
// rightBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
// [cell.layer addSublayer:rightBorder];
// TODO:方法三 kUIColorFromRGB(0xeeeeee).CGColor 这个颜色可以省去上边CALayer
cell.layer.borderColor = kUIColorFromRGB(0xeeeeee).CGColor;
cell.layer.borderWidth = 0.5;
cell.layer.masksToBounds = YES;
[cell setBackgroundColor:[UIColor clearColor]];