2011-12-16 12 views
0

次のコードを使用してUITAbleviewの背景を設定する際に問題があります。 次のコードを使用して、UITable内のセルに代替画像を表示できますか?背景イメージが交互に表示されるUITableviewセル

X.pngを使用しているセル1とY.pngを使用しているセル2?

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

ありがとうございます。まず

+0

あなたが何をしたいかを指定した場合、私はあなたの質問については明らかではないのですか?。 – Emon

+0

不明な質問を申し訳ありませんが、私がしようとしているのは、テーブルを持つことです。各セルの行内には、異なる背景イメージを持つことができますか?例えば最初の行項目がX.pngイメージを使用している場合、2番目の行はY.pngイメージを使用します。出来ますか?おかげで – Clarence

答えて

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。

EDIT:

どんな問題は今でも、このリンクをチェックしhttp://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

+0

素晴らしい!それは働いた!どうもありがとう – Clarence

関連する問題