how to change the color alternate cell on table view

后端 未结 8 1947
一整个雨季
一整个雨季 2021-01-01 02:22

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 wan

8条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 02:30

    If you mean cell's background color, the simplest way to change it:

    cell.backgroundView.backgroundColor = [UIColor greenColor];
    

    It looks like:

    - (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;
    }
    

提交回复
热议问题