3

如果我有一个UITableViewCell不使用textLabel单元格内置的自定义,而是使用它自己的绘图,我该如何更改contentViewon 选择的外观,就像它自动为默认文本所做的那样(可通过设置自定义selectedTextColor:)?

如果我更改tableView:willSelectRowAtIndexPath:,那么它只会在蓝色选择背景启动后更新,而不是在它动画时更新,就像我想要的那样。

4

3 回答 3

6

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

阅读这篇文章了解更多详情。

于 2009-06-17T04:19:48.990 回答
5

在您的 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;
   //-------------------------------------------------------------------------
于 2012-11-16T11:22:09.123 回答
3

如果您已将 UITableViewCell 子类化,则可以通过覆盖以下内容来自定义单元格的元素:

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

    [super setHighlighted:highlighted animated:animated];
}
于 2012-07-24T14:29:16.060 回答