Cell下划线 长度设置为屏幕的宽

//更改tableview分割线颜色等等属性

self.tableView.separatorColor = UIColorFromRGBA(233, 233, 233, 1);

//把tableview分割线长度设为整个屏幕宽

1--

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

{

if (SystemVersion >= 7.0) {

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

[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];

}

if (SystemVersion >= 8.0) {

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

[cell setPreservesSuperviewLayoutMargins:NO];

}

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

[cell setLayoutMargins:UIEdgeInsetsZero];

}

}

}

}

2——

UITableView中将分割线样式改为None

[java] view plain copy

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法

[java] view plain copy

- (void)drawRect:(CGRect)rect

{

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);

CGContextFillRect(context, rect);

//上分割线,

CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);

CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1));

//下分割线

CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor);

CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1));

}

你可能感兴趣的:(Cell下划线 长度设置为屏幕的宽)