2011-03-29 112 views
0

下面是一些我的cellForRowAtIndexPath如何設置表格單元格文本標籤的背景顏色

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
... 


cell.textLabel.textAlignment = UITextAlignmentRight; 
cell.contentView.backgroundColor = [UIColor orangeColor]; 
cell.textLabel.textColor = [UIColor blueColor]; 
cell.textLabel.backgroundColor = [UIColor orangeColor]; 
cell.textLabel.text = @"text"; 


return cell; 
} 

的,因爲它在Interface Builder的定義我的標籤的文本顏色將變爲藍色,但是它的背景色撐!我如何定製它?

回答

0

您是否需要確保不透明度設置正確,可能是透明而不是顏色?

+0

號這表明公司在IB定義標籤的背景,單元格的內容視圖的不是背景的最後的地方。謝謝。 – jkally 2011-03-29 17:25:11

0

嘗試

cell.textLabel.backgroundColor = [UIColor clearColor]; 

編輯:檢查下面SO後,可以對你有所幫助。

UILabel Setting Transparent Background Color?

+0

同樣的事情。謝謝 – jkally 2011-03-29 17:31:13

+0

@Jkally:我看不見邁克Shinoda答案.. – Jhaliya 2011-03-29 17:35:01

+0

@Jkally:檢查更新的答案.. – Jhaliya 2011-03-29 17:42:58

1

OK的朋友,終於找到了。答案是覆蓋willDisplayCell,由於某種原因,就是背景色設置

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.textLabel.backgroundColor = cell.contentView.backgroundColor; 
    cell.detailTextLabel.backgroundColor = cell.contentView.backgroundColor; 

} 
相關問題