2011-12-16 57 views
0

我有一个问题,使用下面的代码来设置UITAbleview的背景。 通过使用下面的代码,我可以在UITable的单元格上有替代图像吗?UITableview单元格与交替背景图像

例如单元格1使用X.png和单元格2使用Y.png?

tableView.opaque = NO; [tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@“wood.png”]]]; cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@“lightwood.jpg”]];

非常感谢。

+0

指定你想要什么,我不清楚你的问题。 – Emon 2011-12-19 05:35:58

+0

对不清楚的问题,我想要做的是有一个表,每个单元格行内可以有不同的背景图像?例如第一行使用X.png图像,第二行使用Y.png图像。可能吗?谢谢 – Clarence 2011-12-19 05:42:46

回答

1

在先来查看您的.h文件中声明UIView *newView;其财产和cellForRowAtIndexPath

if(cell==nil){ 
................ 
......... 
newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)]; 
    [cell.contentView addSubview:newView]; 
................ 
............... 
} 
if(indexPath.row == 0){ 

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]]; 

} 
if(indexPath.row == 1){ 

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]]; 

} 
if(indexPath.row == 2){ 

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]]; 

} 

在您.m文件

synhesize它现在如果还有问题,请把我打倒。

编辑:

如有问题现在仍然然后检查此链接http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html