简体   繁体   English

如何更改仅第一行的UITableView的分隔符颜色?

[英]How to change separator color for UITableView only for first row?

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if indexPath.row == 0 {
        tableView.separatorColor = UIColor.clear
    } else {
        tableView.separatorColor = UIColor.blue
    }
}

I have the above code to change the separator color for only first row. 我上面的代码更改仅第一行的分隔符颜色。 However, the whole section itself turns out with a clear color separator instead of blue. 但是,整个部分本身都带有清晰的分色器,而不是蓝色。 Could you please help me with this. 你能帮我这个忙吗? Any help would be greatly appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

Don't use tableview default seperator. 不要使用tableview默认分隔符。

tableView.separatorColor = UIColor.clear or tableView.separatorStyle = .none

In UITableViewCell add a UIView of 1 px height, give that whatever color you want. UITableViewCell添加一个高度为1 px的UIView ,并根据需要提供任何颜色。 If same UITableViewCell is used for all the table rows, then might be you can use something like - 如果所有表行都使用相同的UITableViewCell ,则可能使用类似-

seperatorView.hidden = indexPath.row != 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM