用颜色部分填充TableView单元格

时间:2013-03-04 07:40:59

标签: iphone ios colors tableview cell

在我的应用程序中,我有tableview,我想根据核心数据的数据填充tableView单元格的颜色。例如,如果单元格包含值50,则用颜色填充半单元格。如果单元格包含值25,则使用颜色填充quater单元格,依此类推。 那么,我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

这可能会解决您的问题。

向表格中添加自定义视图

如果你的值50意味着,

int wd = 50/100*width of tableviewcell;
CGRect rv= CGRectMake(0, 0, wd, height of tableviewcell);
UIView *v=[[UIView alloc] initWithFrame:rv];
v.backgroundColor = [UIColor yourneededcolor];
[[cell contentView] addSubview:v];

并且不要忘记将uitableviewcell的背景颜色设置为clearcolor

相关问题