ios - 仅在 UITableView 中将分隔符添加到第一个单元格

标签 ios swift

我有一个特殊的表格,其中大多数元素使用分隔符看起来很奇怪,所以我禁用了它们。但是,我仍然希望第一个单元格有一个分隔符。我该如何实现?

最佳答案

您可以为您的第一个单元格创建一个自定义的 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/

相关文章:

ios - 如何对字典类型中的特定值求和

ios - 使用 UIWindow() 进行单元测试时出现 NSInternalConsistencyException

ios - 使用 IBInspectable 的选定状态的 UIButton 边框颜色

ios - 自定义tabbar的更多按钮

ios - 同时2个定时器

ios - 错误 :socket select() function always returning zero in iOS system

iphone - iOS:带有按钮图像的导航栏

ios - 使用 Swift 的 NUI?

swift - 如何编写 NSOutlineView?

iphone - 如何释放具有相同委托(delegate)的几个类?