【问题标题】:Removal of white line under section header in UITableView?删除 UITableView 中部分标题下的白线?
【发布时间】:2016-06-28 09:26:49
【问题描述】:

我正在努力删除 UITableView 中每个自定义部分标题下方的白线,如下所示。有什么建议么?我已经在我的 TableView 中使用了它。

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

上面只解决了单元格之间的分隔符,而不是标题。

我的自定义部分标题中唯一的内容是

containerCellView.backgroundColor = UIColor(red: 24/255.0, green: 34/255.0, blue: 41/255.0, alpha: 100)

【问题讨论】:

标签: ios swift uitableview


【解决方案1】:

将页眉和页脚的高度设置为 0.01,它将解决您的问题

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

            return 0.01

    }

【讨论】:

  • 我使用我的标题,所以我最好不要将高度设置为那个?
【解决方案2】:

将此行放入viewDidLoad()

self.tableView.separatorColor = [UIColor clearColor];

【讨论】:

  • 给我一分钟,我会测试它并告诉你
【解决方案3】:

我发现是我的标题单元格的背景颜色导致了问题。

self.backgroundColor = UIColor.blackColor()

解决了自定义头类中的问题

【讨论】:

    【解决方案4】:

    如果您设置了标题,请使用此代码

     headerView.layer.borderColor=[UIColor blackColor].CGColor;         
     headerView.layer.borderWidth=1.0f;
    

    【讨论】:

    • 你已经设置了[UIColor blackcolor];
    • 不起作用,因为我猜它不是真正的分隔符。
    【解决方案5】:

    我能够在 iPhone 7 Plus/iOS 12.1 上重现类似问题。我有一个符合UITableViewDelegate 的类,tableView(_:heightForHeaderInSection:) 是这样实现的:

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 100.0 // any float value
    }
    

    我添加了tableView(_:estimatedHeightForHeaderInSection:) 来解决问题:

    func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
        return 100.0 // any float value
    }
    

    本文中的所有代码都在 Xcode 10.2.1 中进行了测试。我用的是 Swift 5。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2020-08-08
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      相关资源
      最近更新 更多