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;
Related
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.
I have a UIViewController with a UITableView, which is showed from the root view controller. In the simulator everything is working fine, but when testing the app on a real device running iOS7, the background of the UITableView is the same image of the root view. Setting both backgroundColor and backgroundView has no effect. I have also tried to set tableView.opaque = NO and setting the background of the cells, but still not results.
Any ideas on how to fix this behaviour?
Try with this piece of code:
contentTable = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
contentTable.delegate = self;
contentTable.dataSource = self;
[contentTable setBackgroundView:nil];
[contentTable setBackgroundColor:[UIColor blueColor]]; // i.e. Bluecolor as backgrounf
This will return a table with a blue background.
I have a UITableViewController which I initialize with the 'grouped' style.
Why is that as soon as I add either of the following lines, the table view is displayed in 'plain' style with the sticky headers?
self.view.backgroundColor = [UIColor colorWithRed:216/255.0 green:218/255.0 blue:224/255.0 alpha:1.0];
self.tableView.backgroundColor = [UIColor colorWithRed:216/255.0 green:218/255.0 blue:224/255.0 alpha:1.0];
Edit: also, the following does the same.
[self.tableView setBackgroundView:nil];
It turns out that it's because I was doing my customization in initWithNibName:bundle, which I thought was the designated initializer. It works fine if I override initWithStyle:
Anyone care to offer a decent explanation?
i try to set the UITableView Footerview backgroundcolor to clearColor but it stays white, any
other color works fine, any ideas?
_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _incredientsTable.frame.size.width, 60)];
[_footerView setBackgroundColor:[UIColor clearColor]];
Thanks.
Ask yourself these questions:
What do you expect to see through the footer view? Is it the table's background? The underlying view controller's views? In the latter case there are more views between your and the object that you want to be visible under the footer view. That is at least the UITable itself and probably the background of self.view (which in most cases but not all is the table)
You need to set background color of table view in this case.
tblView.backgroundColor = [UIColor clearColor];
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