iOS 8 UITableView background color appearance

18,168

Solution 1

try to "reset" the BackgroundColor to "Default" in the InterfaceBuilder (even if its already Default, you'll see a little color change)

this doesn't works with grouped style tableviews

UPDATE:

this worked for me

[[UIScrollView appearance] setBackgroundColor:[UIColor redColor]];

Solution 2

Clear color for TableViewCell not working in Tablet in XCode 6. The following workaround solve for me.

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

     cell.backgroundColor = [UIColor redColor];
}

Solution 3

It appears that for iOS 8, at least for our circumstances, when we set a view's background color with a table in that view, we have to explicitly set the table and cell background colors to Clear in order for the desired color from the view to show. I suppose, with prior iOS versions, the cells were defaulted to transparent but that seems no longer the case.

Solution 4

Set cell background color to transparent in tableView:willDisplayCell:forRowAtIndexPath:

Solution 5

[UITableVIew backgroundColor] is not marked with UI_APPEARANCE_SELECTOR. Appearance proxies will only work if selector is marked with UI_APPEARANCE_SELECTOR.

Share:
18,168

Related videos on Youtube

HotJard
Author by

HotJard

Updated on June 06, 2022

Comments

  • HotJard
    HotJard almost 2 years

    Xcode 6 beta 6, trying to change all UITableView's background colours in appearance proxy:

    [[UITableView appearance] setBackgroundColor:[UIColor redColor]]
    

    But seems that it doesn't work.

    Steps to reproduce:

    1 Create single view project

    2 Add UITableView to ViewController in storyboard

    3 Set delegates to view controller and change background in IB:

    enter image description here

    4 Add dynamic cell and configure data source:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 2;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      return 2;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1Identifier" forIndexPath:indexPath];
      return cell;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      return 60.f;
    }
    

    5 In app delegate:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      // Override point for customization after application launch.
      [[UITableView appearance] setBackgroundColor:[UIColor redColor]];
    
      return YES;
    }
    

    6 Run app and watch incorrect colour:

    enter image description here

    Any suggestions how to fix it? Setting background color for every table doesn't look like good solution.

    • Yuvrajsinh
      Yuvrajsinh over 9 years
      It occurs only for iOS 8.0.x which was buggy, not producing in lower or greater version of 8.0.x and I think most of the users upgraded to 8.1 so not to worry at all:)
    • Maxim Pavlov
      Maxim Pavlov over 9 years
      According to this question it seems to be a bug. rdar://18406065
    • Ben
      Ben almost 9 years
      I still get the UITableView appearance background color issue in iOS 8.1.X and 8.2.X on physical device and simulator. However it works fine above. I have to keep a [tableview setBackgroundColor: ] programmatically.
    • HotJard
      HotJard almost 9 years
      popei, The question is how to do it automatically in appearance proxy
  • Alex B
    Alex B over 9 years
    Even with default colour, it doesn't work right now.
  • HotJard
    HotJard over 9 years
    but the problem is for grouped style tables
  • Prethen
    Prethen over 9 years
    This did not work for me either. For some reason iOS 8 "broke" the ability to set the background color on the table view for us. Any other ideas?
  • Tony Adams
    Tony Adams over 9 years
    Interesting... I'm seeing it in all my 8.1 simulators.
  • matthias_buehlmann
    matthias_buehlmann over 9 years
    setting appearance of UIScrollView allowed me to change the tableview background color - however, I did not manage to create a tableview with a transparent background (setting SetOpaque on UIScrollView appearance doesn't seem to do the trick)
  • Julian Vogels
    Julian Vogels over 8 years
    This shouldn't be the problem because UITableView inherits from UIView, which has a property backgroundColor marked with UI_APPEARANCE_SELECTOR.