【问题标题】:White line in UITableViewCell?UITableViewCell 中的白线?
【发布时间】:2016-01-31 21:37:33
【问题描述】:

我有一个 UITableViewCell,在 Storyboard 中绘制。

但是,在模拟器上运行它,似乎每个单元格分隔器以及标题单元格分隔器中都有白线。

A 是 UITableViewCell 中的 Header

A11 - A13 是 UITableViewCell 中的内容

如何删除它?我好像找不到任何答案。

更新:

解决方案here 仅将分隔线颜色向左移动,没有边距,并保持标题分隔线保持不变。有什么方法可以在不移动分隔线的情况下去除标题和单元格的白色?

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

您可以简单地选择将表格视图的分隔符设置为“无”。然后子类化 UITableviewCell 并通过将 CALayer 作为子层添加到 awakeFromNib 的单元格来创建边框。

【讨论】:

    【解决方案2】:

    使用 Swift 4.X 并采用最快的黑客方法,您可以使用扩展来改进代码:

        extension UITableViewCell {
    
           var isSeparatorHidden: Bool {
            get {
                return self.separatorInset.right != 0
            }
    
            set {
                if newValue {
                    self.separatorInset = UIEdgeInsetsMake(0, self.bounds.size.width, 0, 0)
                } else {
                    self.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
                }
            }
        }
    }
    

    那么,当你配置单元格时:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifier", for: indexPath)
        switch indexPath.row {
           case 3:
              cell.isSeparatorHidden = true
           default:
              cell.isSeparatorHidden = false
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath)
        if cell.isSeparatorHidden { 
           // do stuff
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多