【问题标题】:UITableView separatorStyle = none vs. separatorColor = .clearUITableView separatorStyle = none vs. separatorColor = .clear
【发布时间】:2019-03-10 20:36:46
【问题描述】:

昨天我看了别人的一个相当大的项目,我注意到任何地方的意图不是让UITableView生成分隔符,而是通过设置tableView.separatorColor = .clear而不是tableView.separatorStyle = .none来完成。

现在我想知道这是否有原因.. 结果是否有所不同,或者更改样式属性是否会因为缺少 0.5p 而以某种方式混淆约束?

【问题讨论】:

标签: ios swift uitableview separator


【解决方案1】:

是的,你的想法是正确的。

tableView.separatorColor = .clear // 清除分隔符背景色

tableView.separatorStyle = .none // 它从父视图中删除分隔符(UITableCell)

案例研究:

考虑UITableViewCell的高度设置为50。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 50
}

如果UITableViewCell 中有UILabel 并且您提供了前导、尾随、顶部和底部 约束,那么tableView.separatorStyle = .none 将不会导致任何约束中断,因为高度为@987654329 @ 将自动增加。

但是如果上述情况如果你也应用了height-constraint,那么计算高度和约束高度会有0.5像素的差异。

不一定每次都会发生,但为了防止这种情况,我们应该使用tableView.separatorColor = .clear

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多