2017-06-17 13 views
1

tableViewに1つおきに1つの色を塗りつぶす方法はありますか? tableViewのプロパティを調べてみましたが、何も見つかりませんでした。TableView他のすべてのセルの1つの色

私はこのようにそれをしたい:

tableview 
cell - white 
cell - gray 
cell - white 
cell - gray 

等...

+0

[代替カラーUITableViewCellはUITableViewにありますか?](https://stackoverflow.com/questions/30505330/color-alternate-uitableviewcell-in-a-uitableview) – ItsMeMihir

答えて

0

最も簡単な方法は、あなたのcellForRowAt機能でプログラムこれを行うには次のようになります。

if indexPath.row % 2 == 0 { 
    cell.backgroundColor = UIColor.white 
} else { 
    cell.backgroundColor = UIColor.gray 
} 
0

一行コード、必要ならば

cell.backgroundColor = indexPath.row % 2 == 0 ? .white : .gray 
関連する問題