UITableView background issue when upgrade iOS7 - ios

I am using UITableView without setting any background color but when I upgrade from iOS6 to iOS7 I found that UITableView misbehaves. The problem is its background color.

You need to set the tableview background color as below
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor];

In iOS7 UITableView default background color is clearColor. So you can change it as following way by adding in viewDidLoad method :
self.tableView.backgroundColor = [UIColor yellowColor];
Here is the good reference
UITableViewCell show white background and cannot be modified on iOS7

Try to set its background color after the table view becomes visible.

Related

Changing the color between NavigationBar and first cell

How can I change the color between NavigationBar and first cell(Space that appears When I scroll down)?
I am creating app with custom tableView with View on top.
I have tried "self.view.backgroundColor = UIColor.green" which did not solve the problem.
Hi all you need to do is change the background colour of your TableView.
In Code:
// OBJ-C
self.tableView.backgroundColor = [UIColor greenColor];
//SWIFT
self.tableView.backgroundColor = UIColor.greenColor
Or in Interface Builder:
Hope that helps
Explanation:

Why is the background of my table view grey when there are no rows?

Why is the background of my table view grey when there are no rows? I can't see where this is set in storyboard
Even setting the background to white explicitly I still get a grey background
Using the defaults for background also results in this grey background:
this might be due to two reason
a) you haven't set data source and delegate and your main view background color is gray
b) cell background color is gray, set that to clear color
Please add this code viewdidload or viewwillappear method
table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
For me it looks like it is a problem of the UITableViewCells, you should set them to
self.backgroundColor = [UIColor whiteColor]; // or clearColor
then also set the UITableView itself inside the controller to backgroundColor white or grey.
Also the snippet of #Rohitsuvagiya can help to let dissappear the separators if there is no additional UITableViewCell.
Please add line your code in viewdidload or viewillappear
table.backgroundColor=[UIColor clearColor];

How to set clearColor for UIPopover View?

I need to set UIPopover background color to clearColor. But rest of all colors are working fine with below code:
myPopover.backgroundColor = [UIColor greenColor];
but when I set clearColor, there is a white background instead of transparent.
Can any one help me. Thanks in Advance!
If what you're talking about is a UIPopoverController, then try setting the background color to its content view controller's view.
myPopover.contentViewController.view.backgroundColor = [UIColor clearColor];
Also, check this SO post about custom popover backgrounds.

table background clear - objective c - cocoa

Hi I want to display my table view without any background color so I used the following code to clear it
[uiTableView setBackgroundColor:[UIColor clearColor]];
This worked fine in the new iPad and also other generation iPads except it failed to work in iPad version one. The table shows with the background gray color. Is this something to do with iOS 5 ? Can anyone let me know if we can clear the background color in first version iPads.
I have noticed the same thing under iOS 5+. Try this:
[uiTableView setBackgroundColor:[UIColor clearColor]];
[uiTableView setBackgroundView:nil];
Should work as intended.
EDIT: If you're using the default cells, they cover the UITableView, so changing the UITableView's background color and view doesn't do anything. Try this in your tableView:cellForRowAtIndexPath: method:
cellName.backgroundColor = [UIColor clearColor];
cellName.backgroundView = nil;
As tableview has one more view as its background. You can set the backgroundColor in two ways.
i) Set the background color for the tableview and set the backgroundView to nil.
[uiTableView setBackgroundColor:[UIColor clearColor]];
[uiTableView setBackgroundView:nil];
ii) Set the backgroundColor for the tableView backgroundView.
UIColor *backgroundColor = [UIColor clearColor];
uiTableView.backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
uiTableView.backgroundView.backgroundColor = backgroundColor;

Change background of a grouped UITableView

I'm having some trouble trying to change the background of a UITableView with groups.
_tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableViewBg.png"]];
This usually works on every other UITableView, but not the one with groups, is there something else I have to do?
In IB I have the background color set to a clear color, but that doesn't do much.
You additionally need to disable the background view of _tableView:
[_tableView setBackgroundView:nil];
_tableView.backgroundColor = [UIColor redColor];
No need to add new view to backgroundView. This is working for me in iOS6.
why don't you set the tableView.backgroundView? you can alloc an image view withe the specified image and pass it to the background view instead of setting the background color.
What I usually do with grouped UITableViews is set the background color to clear, and the set that pattern image to the parents view.
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableBG.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor colorWithPatternImage: xxx];
// tableView.backgroundColor = [UIColor redColor]; // is ok
if you set set the backgroundColor as this, when you scroll the tableView, the backgroundColor view will scroll also. so, you can: tableView.backgroundView = nil; self.view.backgroundColor = ...
The selected answer works but it clears the background of both tableHeaderView and table section header view. If you just want table header to be of a certain color say white and section header still to be default grey than do the following -
tableView.tableHeaderView.inputView.backgroundColor = [UIColor whiteColor];
Just want to add to Nirav's answer - it can also be done using the iOS 5 appearance proxy.
[[UITableView appearance] setBackgroundView:nil];
[[UITableView appearance] setBackgroundColor:[UIColor lightGreyColor]];
The advantage is that it is applies globally, so you can group all your UI customisations in one place. However, it will apply to all tableViews (not just grouped style).
For iOS 9+, changing the background color of the UITableView is enough.
Objective-C
tableView.backgroundColor = [UIColor redColor];
Swift
tableView.backgroundColor = .red
Swift 4.2
TO REMOVE BACKGROUND VIEW & COLOR
tableView.backgroundView = nil
tableView.backgroundColor = .clear

Resources