2011-04-15 141 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中设置图像。它将作为背景图像... :)