Search code examples
iphoneioscolorstableviewcell

Partly filling TableView cell with color


In my app I have tableview and I want to fill tableView cell with color depending on core data's data. For example, if a cell contain a value 50, I fill half cell with color. If the cell contain a value 25, I fill quater cell with color and so on. So, how can I do that?


Solution

  • This may give a solution to your problem.

    Add a custom view to the table vie cell

    if ur value 50 means,

    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];
    

    and don't forget to set the background color of uitableviewcell to clearcolor.