2014-04-01 31 views
0

我设置一个自定义的UITableViewCell选择颜色如下:自定义的UITableViewCell,突出了色彩

cell.contentView.backgroundColor = [[UIColor alloc]initWithRed:250.0/255.0 green:250.0/255.0 blue:250.0/255.0 alpha:1]; 

    UIView *bgColorView = [[UIView alloc] init]; 
    bgColorView.backgroundColor = [UIColor colorWithRed:(240.0/255.0) green:(240.0/255.0) blue:(240.0/255.0) alpha:1.0]; 
    bgColorView.layer.masksToBounds = YES; 
    cell.selectedBackgroundView = bgColorView; 

这工作完全,只是因为我的UITableViewCell的常规背景颜色不是白色,当亮点后淡出发生去白色,然后我的背景颜色,而不是退色到我的背景颜色。有人知道如何解决这个问题吗?

+0

向我们展示整个cellForRowAtIndexPath方法 – Vame

回答

2

改为设置backgroundView,而不是设置contentView的背景颜色。

UIView *bgView = [[UIView alloc] init]; 
bgView.backgroundColor = [[UIColor alloc]initWithRed:250.0/255.0 green:250.0/255.0 blue:250.0/255.0 alpha:1]; 
cell.backgroundView = bgView; 

UIView *bgColorView = [[UIView alloc] init]; 
bgColorView.backgroundColor = [UIColor colorWithRed:(240.0/255.0) green:(240.0/255.0) blue:(240.0/255.0) alpha:1.0]; 
bgColorView.layer.masksToBounds = YES; 
cell.selectedBackgroundView = bgColorView; 
+0

这个工作完美。非常感谢 – Apollo

0

的背景由你tableview:cellFor...返回后,它的实现代码如下设置。因此,单元格背景定制应该在tableView:willDisplayCell:...