我有一个特殊的表格,其中大多数元素使用分隔符看起来很奇怪,所以我禁用了它们。但是,我仍然希望第一个单元格有一个分隔符。我该如何实现?
最佳答案
您可以为您的第一个单元格创建一个自定义的 UITableViewCell
类,并覆盖 drawRect:
以便在底部(或任何您想要分隔符的地方)画一条线
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetStrokeColorWithColor(context, [_lineColor CGColor]);
CGContextSetLineWidth(context, _lineHeight);
// Bottom line
CGContextMoveToPoint(context, 0.0, self.bounds.size.height);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height);
CGContextDrawPath(context, kCGPathStroke);
}
关于ios - 仅在 UITableView 中将分隔符添加到第一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32168813/