美文网首页
Cell下划线 长度设置为屏幕的宽

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

作者: 然亦伞 | 来源:发表于2016-03-14 20:41 被阅读230次

//更改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下划线 长度设置为屏幕的宽

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