2014-04-01 68 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:...