我创建了一个 UITableView,但分隔符有问题。我对其进行了自定义,使其显示为灰色且没有插图:
self.tableView.separatorInset = .zero
self.tableView.separatorColor = AppColors.separatorColor
我也试过一张图片:
self.tableView.separatorInset = .zero
tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
tableView.separatorColor = UIColor(patternImage: #imageLiteral(resourceName: "thin_divider"))
问题:选择一行时,分隔符变为白色。我玩过 didSelectRowAt、didDeselectRowAt 和 didHighlightRowAt 但无事可做,当单元格被选中时它保持白色。请参阅下面的示例(在此示例中选择了最后一个单元格)...
最佳答案
在 cellForRowAtIndexPath
方法中尝试此代码行
[cell setSelectionStyle: UITableViewCellSelectionStyleNone];
这会将 none 设置为选择样式(此属性的默认值为 UITableViewCellSelectionStyleBlue
)。
对于单元格高亮部分,在 didSelectRowAtIndexPath
中使用以下代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setHighlighted: NO];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
希望这对您有所帮助。
关于ios - 选择单元格时 UITableView 分隔符颜色发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40126756/