2011-12-16 52 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