如何更改表视图上的颜色交替单元格 [英] how to change the color alternate cell on table view
本文介绍了如何更改表视图上的颜色交替单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中显示表格视图单元格的数据,所以我想根据第一个单元格灰色的数据方式给单元格颜色然后再下一个棕色的两个单元格我想要显示灰色单元格,
这样可以任何人告诉我最简单的程序是什么。
I want to display data on table view cell from database so i want to give the color to cell according to data means for 1st cell gray then next two cell in brown again i want display gray cell, so can any one tell me what is the simplest procedure for it.
thnks&问候,
Priyanka。
thnks & regards, Priyanka.
推荐答案
如果你的意思是细胞的背景颜色,最简单的改变方法是:
If you mean cell's background color, the simplest way to change it:
cell.backgroundView.backgroundColor = [UIColor greenColor];
看起来像:
- (UITableViewCell *) tableView:tableView cellForRowAtIndexPath:indexPath
{
cell = ... // dequeue or initialize cell
switch (criteriaFromDatabase)
{
case 0:
cell.backgroundView.backgroundColor = [UIColor greenColor];
break;
case 1:
cell.backgroundView.backgroundColor = [UIColor blueColor];
break;
default:
cell.backgroundView.backgroundColor = [UIColor redColor];
break;
}
return cell;
}
这篇关于如何更改表视图上的颜色交替单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文