2012-03-27 53 views
0

我一直在使用默認顏色灰色和藍色的單元格選擇,但我想嘗試一個明亮的橙色,但我不知道如何做自定義的UITableview選擇。自定義selectionStyle顏色爲uitableviewcell

這是我使用此刻的代碼..

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
cell.selectionStyle = UITableViewCellSelectionStyleGray; 

我也曾嘗試

[cell setSelectionStyle:[UIColor orangeColor]]; 

,但我得到一個警告說setSelectionStyle不是整數的東西。

回答

1

你會得到該錯誤,因爲程序期望UITableViewCellSelectionStyle你給它一個UIColor。我不知道是否有辦法以編程方式做到這一點,但你可以嘗試使用單元格的selectedBackgroundView財產使用自己的形象:

cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImageHere.png"]] autorelease]; 

這會去你的cellForRowAtIndexPath方法。