美文网首页redexpress的收藏UI效果
UITableViewCell的分割线样式

UITableViewCell的分割线样式

作者: JamesGu0116 | 来源:发表于2015-09-07 18:11 被阅读985次

默认UITableViewCell是留有图标区域的,但是要是不加图标,就会在左边留有一段空间,很不好看。所以,我们定义一个UITableViewCell的子类,在.m的实现里填上下边这段方法,给它画一个分割线。

-(void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    CGContextRef cxt = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(cxt, 0.5);
    CGContextSetStrokeColorWithColor(cxt, [UIColor colorWithWhite:0.910 alpha:1.000].CGColor);
    CGContextMoveToPoint(cxt, 0.0 , self.frame.size.height - 0.5);
    CGContextAddLineToPoint(cxt,self.frame.size.width , self.frame.size.height - 0.5);
    CGContextStrokePath(cxt);
}

千万记得在UITableView上关掉原本的Cell分割线样式

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

相关文章

网友评论

    本文标题:UITableViewCell的分割线样式

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