Reputation: 4798
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:
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:
Any suggestions how to fix it? Setting background color for every table doesn't look like good solution.
Upvotes: 20
Views: 18283
Reputation: 311
[UITableVIew backgroundColor] is not marked with UI_APPEARANCE_SELECTOR. Appearance proxies will only work if selector is marked with UI_APPEARANCE_SELECTOR.
Upvotes: 1
Reputation: 2323
Set cell background color to transparent in tableView:willDisplayCell:forRowAtIndexPath:
Upvotes: 1
Reputation: 3968
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];
}
Upvotes: 5
Reputation: 173552
It seems that the appearance proxy exhibits a seemingly unreported bug in iOS 8.0.x; it's unrelated to the iOS 7 change involving the default background colour of table cells.
The relative good news is that this only seems to be an issue between iOS 8.0 and 8.0.2, because:
Until most users have upgraded you will have to set the background explicitly on the object itself, sending us back into the pre-appearance era :(
Upvotes: 0
Reputation: 2827
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]];
Upvotes: 12
Reputation: 277
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.
Upvotes: 2