设置自定义表格视图单元格的背景图像

msk*_*msk 2 iphone cocoa-touch image uitableview

我已尝试过多种方法来设置未选择的表格单元格的背景图像,但没有成功:

1- In IB setting the image field
2- cell.contentView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"list.png"]];
3- cell.imageView.image = [UIImage imageNamed:@"list_selected.png"];
Run Code Online (Sandbox Code Playgroud)

一切似乎都失败了.所选单元格的图像设置有效,但不适用于未选择的单元格.有谁知道这里可能有什么问题?

谢谢

ger*_*ry3 19

尝试将backgroundView设置为图像的imageView.

Jason Moore的代码示例(与TomH的更正):

cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]] autorelease];
Run Code Online (Sandbox Code Playgroud)

  • cell.backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]]; (2认同)