Ios 选择单元格时如何更改蓝色高亮显示颜色

Ios 选择单元格时如何更改蓝色高亮显示颜色,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我知道它可能是重复的,但我想知道选择单元格时更改蓝色高光颜色的最佳和最快方法 当然,我已经尝试过(而且很有效)在选中单元格时改变背景颜色的方法(如下图所示),但我不喜欢这种方法,我更喜欢真正改变突出显示的颜色 有什么联系或想法吗?谢谢。在tableview的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 创建uiimageview并将其

我知道它可能是重复的,但我想知道选择单元格时更改蓝色高光颜色的最佳和最快方法

当然,我已经尝试过(而且很有效)在选中单元格时改变背景颜色的方法(如下图所示),但我不喜欢这种方法,我更喜欢真正改变突出显示的颜色

有什么联系或想法吗?谢谢。

在tableview的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
创建uiimageview并将其背景色更改为所需颜色

if (cell == nil) {
    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor greenColor];
    cell.selectedBackgroundView = bgView;
}

首先,必须创建具有相同大小单元的视图。将背景色应用于该视图。然后在cellForRowAtIndexpath委托方法中将视图设置为单元格的选定背景

[cell setSelectedBackgroundView:yourView];

如果您使用nib创建表视图单元格,那么在单元格的属性检查器中,您可以看到一个属性“selection”。将此设置为“无”

如果您是以编程方式创建的,则将单元格设置为

yourCell.selectionStyle = UITableViewCellEditingStyleNone;

用这个方法写这些行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath



if (cell == nil) 
{
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];

    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView  = bgView;
}

您可以使用所需颜色将新UIView指定给单元格的selectedBackgroundView。 Swift 3

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "departmentCell", for: indexPath)

        let selectedView = UIView(frame: cell.frame)
        selectedView.backgroundColor = ColorKit.cellSelectionColor
        cell.selectedBackgroundView = selectedView



        return cell
    }

您可以向tablecell提供选定的背景视图。这是最正确的方法。你如何创建你的表视图..蓝色是相对于
selectedBackgroundView
属性的?@Lucien应用这个答案。它很完美。是的,我没有看这个,最好的答案(对我来说)不是应用的。嗯,这是一个好答案,但是如果我想保持色调效果呢/