为单个UITableViewCell更改UITableView separatorColor [英] Change the UITableView separatorColor for a single UITableViewCell

查看:98
本文介绍了为单个UITableViewCell更改UITableView separatorColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView ,它使用各种自定义 UITableViewCells

I have a UITableView that uses a variety of custom UITableViewCells.

我希望能够让其中一个表格单元格显示出与其他单元格不同的分隔符颜色。

I'd like to be able to have one of these table cells appear with a different separator color than the rest of the other cells.

I知道 tableview.seperatorColor 更新整个 tableView 。是否存在我遗漏的细胞特定属性或其他方法?

I know that tableview.seperatorColor updates the whole tableView. Is there a cell specific property I missing or another approach to doing this?

感谢您的任何提示。很抱歉,如果我只是在 UITableViewCell 类中的某些内容。

Thanks for any tips. Sorry if I am just spacing on something in the UITableViewCell class.

推荐答案

免责声明 - 在我的具体情况下,这对我来说当时。它不能保证工作,似乎不再有效,我现在建议您继承 UITableViewCell

Disclaimer - this worked for me at the time under my specific circumstances. It is not guaranteed to work, it appears to no longer work, and I now advise you subclass UITableViewCell.

想要在分组 UITableView UITableView.separatorColor 时,看到了这篇文章>。

Came across this post when looking to set the UITableView.separatorColor differently across groups/sections in a grouped UITableView.

您不一定需要继承 UITableViewCell 。您可以尝试在每次调用 tableView:cellForRowAtIndexPath:时设置 tableView.separatorColor

You don't necessarily need to subclass UITableViewCell. You can try setting tableView.separatorColor on each call to tableView:cellForRowAtIndexPath:.

例如,如果您希望分隔符在第一部分中以默认颜色可见,则在第二部分的第一行/单元格中可见,而在第二部分的其余行中不可见部分,您可以执行以下操作:

For example, if you want the separator to be visible with the default color in the first section, visible in the first row/cell of the second section, and invisible in the rest of the rows in the second section, you can do the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
    case 0:
        tableView.separatorColor = nil;
        break;
    case 1:
        switch (indexPath.row) {
            case 0:
                tableView.separatorColor = nil;
                break;
            case 1:
                tableView.separatorColor = [UIColor clearColor];
                break;
            default:
                break;
        }
        break;
    default:
        break;
}

这篇关于为单个UITableViewCell更改UITableView separatorColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆