细胞中的内容与中心对齐。这导致细胞被不需要的空白区域分开。
我试过以下代码
在viewDidLoad中
tableView.layoutMargins = UIEdgeInsets.zero
tableView.separatorInset = UIEdgeInsets.zero
tableView.separatorStyle = .none
在cellForRowAt中
cell.layoutMargins = UIEdgeInsets.zero
cell.separatorInset = .zero
我正在寻找一种实用方法来自定义单元格之间的空间。
请在下面找到图片
细胞之间具有完全0
空间,因此细胞本身必须具有顶部/底部边缘。
要简单地测试我刚刚说过的内容,请将单元格的背景设置为.red
。如果我错了,红细胞之间会有白色条纹。
为了正确:
automaticDimension
或自行计算行高并对其进行硬编码。使用tableView:heightForRowAtIndexPath:
。这使您可以设置大小,而不管单元格中的内容如何。
根据您的单元格配置,也许设置automaticDimension
可以解决它:
self.tableView.rowHeight = UITableView.automaticDimension
否则,您可能希望降低单元格高度:
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CELL_HEIGHT_VALUE
}
希望这可以帮助。