Change background of a grouped UITableView - ios

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

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:

UITableView background issue when upgrade iOS7

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.

Why does setting a background color on a tableview change its style?

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?

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;

How can I the change text color of the cells of a UITableView?

I have added some data in UITableView, and I want to change the color of the text displayed in the cells.
Is there a delegate method for doing this, or any other way?
NO need for Labels
You just need to code :
cell.textLabel.textColor = [UIColor redColor];
or if you want to change the detailTextLabel :
cell.detailTextLabel.textColor = [UIColor blueColor];
good luck
You can add labels in the cell and set the color for these labels according to you .And also you can add more than one label and customize the cell.
simply use this line
cellLabel.textColor=[UIColor redColor]; //according to you.
The code according to hex number of color code
Use this code
If color code is: #4B4B4B so Red:75 Green:75 Blue:75
cell.textLabel.textColor =
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1];

Resources