代码之家  ›  专栏  ›  技术社区  ›  Sophie Alpert

UITableViewCell的选择颜色

  •  3
  • Sophie Alpert  · 技术社区  · 17 年前

    如果我有习惯的话 UITableViewCell 那不使用 textLabel 内置于单元格中,但它自己绘制,如何更改 contentView 在选定内容时,与默认文本自动相同(可通过设置 selectedTextColor: )?

    如果我改变 tableView:willSelectRowAtIndexPath: ,然后它只会在蓝色选择背景打开后更新,但不会像我想要的那样在动画时更新。

    3 回复  |  直到 13 年前
        1
  •  6
  •   Thomas    17 年前

    只是不要子类UITableViewCell并使用默认行为。 您可以完全自定义一个单元格,而无需任何子类化。

    this article 了解更多详细信息。

        2
  •  5
  •   Sunil Targe    13 年前

    在TableView CellForRowatindexPath方法中添加此代码,只需更改UITableViewCell选择样式的预期颜色。

       //-------------------------------------------------------------------------
       //background selected view 
       UIView *viwSelectedBackgroundView=[[UIView alloc]init];
       viwSelectedBackgroundView.backgroundColor=[UIColor colorWithRed:124.0/255.0 green:202.0/255.0 blue:227.0/255.0 alpha:1.0];
       cell.selectedBackgroundView=viwSelectedBackgroundView;
       //-------------------------------------------------------------------------
    
        3
  •  3
  •   Willster justkt    13 年前

    如果已对UITableViewCell进行了子类化,则可以通过重写以下内容自定义该单元格的元素:

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
        if(highlighted) {
            self.backgroundColor = [UIColor redColor];
        } else {
            self.backgroundColor = [UIColor clearColor];
        }
    
        [super setHighlighted:highlighted animated:animated];
    }