-3

Possible Duplicate:
How to customize the background color of a UITableViewCell?

I am trying to set the text color of a cell but it is not working. Here is the code..

cell_center.backgroundColor = [UIColor redColor];
cell_center.textLabel.backgroundColor = [UIColor grayColor];
cell_center.selectionStyle = UITableViewCellSelectionStyleGray;

Here selection style is working but text color not affecting. Any idea what I am doing wrong?

Community
  • 1
  • 1
Feroz
  • 699
  • 5
  • 17
  • 25
  • @HelmiB Not like that, I have asked few questions only, one or two questions I got proper answer, remaining it didn't worked for me. Now here its worked thanks for that. :) – Feroz Aug 02 '12 at 07:27

4 Answers4

9

Set the background color of contentView like this:

[cell_center contentView].backgroundColor = [UIColor redColor];
pasawaya
  • 11,515
  • 7
  • 53
  • 92
Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41
2
cell_center.textLabel.textColor = [UIColor redColor];
HelmiB
  • 12,303
  • 5
  • 41
  • 68
0

You actually wanted to set your TEXT color but you did not even do that. Try this:

cell_center.textLabel.textColor = [UIColor blackColor];
Rick
  • 1,818
  • 1
  • 15
  • 18
-2

Looks like the other answers are showing how to change the cell background color, not the label background color.

To change the label background color, use the following code.

[cell_center.textLabel setBackgroundColor:[UIColor grayColor]];

Let me know if this doesn't work for you and we'll troubleshoot some more.

Baub
  • 5,004
  • 14
  • 56
  • 99