how to change the color alternate cell on table view

后端 未结 8 1854
一整个雨季
一整个雨季 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:45
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row % 2==0) 
        {
             cell.contentView.backgroundColor = [UIColor grayColor];  // first color (greyColor or grayColor can't remember spelling)
        }
        else 
        {
             cell.contentView.backgroundColor = [UIColor brownColor];  // second color
        }
    }
    
    0 讨论(0)
  • 2021-01-01 02:46


    write below code

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row%2==0) 
        {
            //Write your code for even rows like 0,2,4
        }
        else 
        {
             //write your code for odd rows like 1,3,5
        }
    }
    
    0 讨论(0)
提交回复
热议问题