how to change the color alternate cell on table view

后端 未结 8 1940
一整个雨季
一整个雨季 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:38

    Mitesh Khatri's answer worked for me, although I changed the order of colors used to white as the second color as seen below for what I thought was a better UI. I also used a uicolor generator at www.UIColor.org to find just the right color for my needs. Hopes this helps.

    • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

      if (indexPath.row % 2 == 0) {
          [cell setBackgroundColor:[UIColor colorWithRed:81.0/255.0 green:102.0/255.0 blue:145.0/255.0 alpha:0.1]];
      }
      else {
          [cell setBackgroundColor:[UIColor whiteColor]];
      

提交回复
热议问题