uiTableViewがあります。お互いのセルに別の背景色を付けてほしい。私はこのようにそれを試みています。しかし、それは機能しません。誰か手がかりがありますか?
if(indexPath.row % 2 == 0){
cell.backgroundColor = [UIColor whiteColor];
}else{
cell.backgroundColor = [UIColor blueColor];
}
敬具、
ステフ
uiTableViewがあります。お互いのセルに別の背景色を付けてほしい。私はこのようにそれを試みています。しかし、それは機能しません。誰か手がかりがありますか?
if(indexPath.row % 2 == 0){
cell.backgroundColor = [UIColor whiteColor];
}else{
cell.backgroundColor = [UIColor blueColor];
}
敬具、
ステフ
内部cell.contentView.backgroundColor
の代わりに:を使用できますcell.backgroundColor
tableView:cellForRowAtIndexPath:
または:(Appleドキュメントから)
注:セルの背景色を変更する場合(UIViewで宣言されたbackgroundColorプロパティを使用してセルの背景色を設定することにより)、tableViewではなくデリゲートのtableView:willDisplayCell:forRowAtIndexPath:メソッドで変更する必要があります。 :cellForRowAtIndexPath:データソースの。グループスタイルのテーブルビューのセルの背景色を変更すると、iOS 3.0では、以前のバージョンのオペレーティングシステムとは異なる効果があります。長方形の外側の領域ではなく、角の丸い長方形の内側の領域に影響するようになりました。
cell.backgroundView=[[UIView alloc]initWithFrame:cell.frame];
[cell.backgroundView setBackgroundColor:[UIColor blueColor]];
仕事をするか
[cell.contentView setBackgroundColor:[UIColor blueColor]];
コメントで拡張された質問に答えるには、ラベルの背景色を次のように設定しますlabel.backgroundColor = [UIColor clearColor];