UITableView cell background color

前端 未结 8 678
别那么骄傲
别那么骄傲 2020-12-08 03:13

how to set different background colors for cells in a UITableView (specifically rainbow color for seven cells)

相关标签:
8条回答
  • 2020-12-08 03:45

    You can set it like so:

    cell.contentView.backgroundColor = [UIColor colorWithRed:249.0/255 green:237.0/255 blue:224.0/255 alpha:1.0];
    
    0 讨论(0)
  • 2020-12-08 03:45

    You may arrive at the conclusion that 'willDisplayCell' is still not working like I did at first. The reason it didn't work for me initially was because I wasn't using colors properly.

    Don't forget that when using custom colors you need to divide by 255.0f:

    [UIColor colorWithRed:44/255.0f green:50/255.0f blue:65/255.0f alpha:1];

    Something like the following will result to a white cell:

    //DON'T DO [UIColor colorWithRed:44 green:50 blue:65 alpha:1];

    making it look like it's not doing anything when it really is setting the background to white.

    0 讨论(0)
提交回复
热议问题