是否可以增加UITableView分隔线的厚度?

Kex*_*Kex 10 xcode uitableview ios

我到处寻找.试图增加这条线的厚度.无论如何以编程方式执行此操作?谢谢

jhe*_*ran 12

这样做的唯一方法是将separtorStype设置为UITableViewCellSeparatorStyleNone,然后你有两个选择:

  • 创建一个自定义UITableViewCell,其中包含分隔符或
  • 使用所需的分隔符创建备用UITableViewCell,并将其放在每个其他单元格中.如果要在表格上显示3行,则应显示5而不是第2行和第4行中的备用单元格.


Chi*_*buZ 6

private let kSeparatorId = 123
private let kSeparatorHeight: CGFloat = 1.5

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
    if cell.viewWithTag(kSeparatorId) == nil //add separator only once
    {
        let separatorView = UIView(frame: CGRectMake(0, cell.frame.height - kSeparatorHeight, cell.frame.width, kSeparatorHeight))
        separatorView.tag = kSeparatorId
        separatorView.backgroundColor = UIColor.redColor()
        separatorView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

        cell.addSubview(separatorView)
    }
}
Run Code Online (Sandbox Code Playgroud)