我想將cell
的color
設置爲透明黑色。我怎樣才能做到這一點?如何將單元格的背景顏色設置爲有色黑色
我試圖將alpha
設置爲.5,但它不起作用。
cell.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5];
我想將cell
的color
設置爲透明黑色。我怎樣才能做到這一點?如何將單元格的背景顏色設置爲有色黑色
我試圖將alpha
設置爲.5,但它不起作用。
cell.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5];
cell.background-color: transparent;
將頁面background-color
設置爲黑色?
在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];
放在正確的地方,它應該如你所願地工作。
另一種選擇是使用選定的顏色或漸變爲您設置背景視圖。
設置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]];
}
它現在可以工作。覈實。
不,tableView背景將是一個圖像,並且這些單元格將是半透明的黑色。就像一個有色的窗戶。 – 2011-03-01 01:56:39