2011-03-01 131 views

回答

0

cell.background-color: transparent;將頁面background-color設置爲黑色?

+0

不,tableView背景將是一個圖像,並且這些單元格將是半透明的黑色。就像一個有色的窗戶。 – 2011-03-01 01:56:39

3

UITableViewCell Class Reference,有以下注意事項:

注意:如果你想改變一個單元格的背景色(通過經由UIView宣佈backgroundColor屬性設置單元格的背景色)您必須在代理的tableView:willDisplayCell:forRowAtIndexPath:方法中執行此操作,而不是在數據源的tableView:cellForRowAtIndexPath:中執行此操作。在iOS 3.0中,對組合式表格視圖中單元格的背景顏色的更改與以前版本的操作系統不同。它現在會影響圓角矩形內的區域,而不是其外部的區域。

因此,把代碼cell.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5];放在正確的地方,它應該如你所願地工作。

另一種選擇是使用選定的顏色或漸變爲您設置背景視圖。

1

設置tableView的'willDisplayCell'委託方法的單元格背景顏色。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell 
               forRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cell setBackgroundColor:[UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5]]; 
} 

它現在可以工作。覈實。

相關問題