Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I have a View with two table views inside it. I want to set top of table view's background to cyan color, I used code as below, the cell color is getting to cyan, but the table view didn't, how can I set it to cyan color?
Code:
    tableView.backgroundColor = UIColor.cyanColor;

    cell.labelDate.backgroundColor = [UIColor cyanColor];	
    cell.labelOpen.backgroundColor = [UIColor cyanColor];	
    cell.labelHigh.backgroundColor = [UIColor cyanColor];	
    cell.labelLow.backgroundColor = [UIColor cyanColor];	
    cell.labelClose.backgroundColor = [UIColor cyanColor];	
    cell.labelVolume.backgroundColor = [UIColor cyanColor];
 

Attachments

  • SnapShot 2010-09-08 at 22.17.56.jpg
    SnapShot 2010-09-08 at 22.17.56.jpg
    52.9 KB · Views: 106
  • SnapShot 2010-09-08 at 22.18.10.jpg
    SnapShot 2010-09-08 at 22.18.10.jpg
    88.4 KB · Views: 94
  • SnapShot 2010-09-08 at 22.14.40.jpg
    SnapShot 2010-09-08 at 22.14.40.jpg
    57.3 KB · Views: 101

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
That looks to me like you want to set the background color of the table cell.
Top table is only one row, I want to whole row background is set, though I can set cell background color, but there is gap between cells, I hope that gap is also the same background color, may I make sense?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
There's also a problem where the table sets the background color of cells because, well because, it feels like it. To adjust for this you have to set the background color of cells in the willDisplayCell callback. Maybe that's the problem.
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
There's also a problem where the table sets the background color of cells because, well because, it feels like it. To adjust for this you have to set the background color of cells in the willDisplayCell callback. Maybe that's the problem.

This. I believe the intention is for the background colour to match the background of the content view for consistency, which is why UITableView does this.

Like you say, you should set this kind of stuff in willDisplayCell as its the last thing to be called before the cell is displayed.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I think the reason it does this is related to selection of the cells. Apple considers the background color of the cell to be "state" of the cell and reserves the right to change it. This changed in OS 3.2. Prior to that setting the background color could be done once and it would stay set. On the Apple iPhone forum after some complaints about this new behavior replied that Apple had always reserved the right to change the background color of cells.

I think this is a bad design. No other views get their background colors changed arbitrarily. UIButton is a good comparison. It does get its appearance changed in response to touches. It has properties that describe the background color depending on the state of the button. UITableViewCell should have something similar. Nevertheless, it is what it is.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.