【问题标题】:How to change blue highlight color when a cell is selected选择单元格时如何更改蓝色突出显示颜色
【发布时间】:2013-05-17 05:32:00
【问题描述】:

我知道这可能是重复的,但我想知道在选择单元格时更改蓝色突出显示颜色的最佳和最快方法。

诅咒,我已经尝试过(并且有效)在选择单元格时更改背景颜色(像这样thread)但我不喜欢这种方式,我宁愿真的改变这个高亮颜色。

任何链接或想法?谢谢。

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

您可以将新的 UIView 分配给具有所需颜色的单元格的 selectedBackgroundView。 斯威夫特 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
    }

【讨论】:

    【解决方案2】:

    在这个方法中写下这些行

    - (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;
    }
    

    【讨论】:

      【解决方案3】:

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

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

      yourCell.selectionStyle = UITableViewCellEditingStyleNone;
      

      【讨论】:

        【解决方案4】:

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

        [cell setSelectedBackgroundView:yourView];
        

        【讨论】:

          【解决方案5】:

          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;
          }
          

          【讨论】:

          • @Lucien 应用这个答案。它是完美的。
          • 是的,我没有看这个thread,最好的答案(对我来说)不是应用的那个。
          • 嗯,这是一个很好的答案,但如果我想保持色调效果怎么办? ://
          猜你喜欢
          • 2011-02-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-01-18
          • 2014-05-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多