Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 UITableView background color appearance

Tags:

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.

like image 801
HotJard Avatar asked Aug 27 '14 15:08

HotJard


2 Answers

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]];
like image 114
Chakalaka Avatar answered Sep 25 '22 13:09

Chakalaka


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];
}
like image 27
Thein Avatar answered Sep 24 '22 13:09

Thein