2011-04-15 98 views
1

我試圖得到了每一個細胞自身的背景,但它看起來像:單元格背景

example cell image

這裏是我與

cell.team1Label.backgroundColor = [UIColor clearColor]; 
cell.team2Label.backgroundColor = [UIColor clearColor]; 
cell.dateLabel.backgroundColor = [UIColor clearColor]; 
cell.timeLabel.backgroundColor = [UIColor clearColor]; 
cell.stadiumLabel.backgroundColor = [UIColor clearColor]; 

cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell.png"]]; 

感謝

回答

3

望着UITableViewCell類的引用,有一個名爲backgroundView屬性,它應該是你要找的東西。

UIImageView *background = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"image"]; 
[cell setBackgroundView: background]; 
[background release]; 

有一個稱爲selectedBackgroundView以及屬性,它是用來代替常規一個,當選擇了小區/突出顯示。

編輯:只是試過這段代碼,至少它的工作時,單元格內有一個標籤。不確定多個,但如果您沒有添加任何其他視圖到單元格,它應該按預期工作。

+1

「任何其他視圖」我的意思是容器視圖,其中包含所有標籤或類似的東西。如果有任何這些,你應該將他們的backgroundColor設置爲[UIColor clearColor] – 2011-04-15 20:33:05

+0

有一點需要注意的是與tableview單元格中使用的透明視圖相關的潛在性能損失。文檔引述如下:「如果你確實採用這種方法,儘可能避免使視圖透明。透明子視圖會因合成成本增加而影響滾動性能」http://developer.apple.com/library/ios/文檔/ UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#// apple_ref/doc/uid/TP40007451-CH7-SW15 – 2011-04-16 06:48:29

+0

實際情況並不差,但是,使用不透明圖像會是一個更好的性能決定。 – 2012-04-29 15:24:54

0

嘗試使用的代碼

cell.backgroundColor = [UIColor colorwithPatternImage:[UIImage imageNamed:@"cell.png"]]; 
+0

沒什麼,但背景現在完全白色。 – 2011-04-15 19:13:20

1

補充一點:

cell.contentView.backgroundColor = [UIColor clearColor]; 
cell.backgroundColor = [UIColor colorWithPatternImage... 
+0

什麼也沒有,但背景現在完全白色。 – 2011-04-15 19:11:43

0

如果您正在創建自定義單元格,那麼您可以在單元格本身的uiimageview中設置圖像。它將作爲背景圖像... :)