具有交替背景图像的UITableview单元格

时间:2011-12-16 14:05:58

标签: uitableview

使用以下代码设置UITAbleview的背景时出现问题。 我可以使用以下代码在UITable内的单元格上有替代图像吗?

e.g。单元格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”]];

非常感谢。

1 个答案:

答案 0 :(得分:1)

首先在.h文件中查看视图UIView *newView;声明其属性并在.m文件中将其同步

现在在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"]];

}

如果有任何进一步的问题请敲我。

编辑:

如果现在仍有问题,请查看此链接http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

相关问题