Take the 2-minute tour ×

I have a navigation based app where I push UITableViewControllers onto the stack. I would like to add a background UImage to all of my UITableViewControllers. Not a UIColor, but an UImage. I know how I can do this using a Nib file and setting the UITableView itself to have use [UIColor ClearColor], but I don't want to go through all my UITableViewControllers and change them to using Nib files, etc.

I also found this solution which would be great if I was just using a single tableviewcontroller in my app. I think there might be a way to make this work, by adding a subview "below" my table view that is created by default in a UITableViewController?

Any suggestions would be great.

share|improve this question
add comment

6 Answers

up vote 36 down vote accepted

It's a little different in a navigation based app: just change the background of the navigation view that each table view is sitting on. Placing the following code in viewDidLoad of each UITableViewController works:

self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]]; self.tableView.backgroundColor = [UIColor clearColor];

But you may only need to do it once, at the top level of the navigation controller, rather than in each tableview controller (although you'll still have to set each background to clear).

share|improve this answer
That's exactly it. thanks very much. –  hookjd Dec 1 '09 at 23:22
In addition I needed a 3rd line: self.view.backgroundColor = [UIColor clearColor]; –  pulkitsinghal May 17 '12 at 17:49
This doesn't push the background image down to the bottom of a nav bar like a viewcontroller does... –  yourfriendzak May 22 '12 at 21:19
I am using this in my tableVC: [self.tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]]]; works like a charm ;) –  raistlin Sep 6 '12 at 10:39
Doesn't seem to work with iOS 6 –  Steve Moser Sep 20 '12 at 20:34
show 2 more comments

On iOS6 use this:

UIImageView *boxBackView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TextureBoxboard.jpg"]];
[self.tableView setBackgroundView:boxBackView];
share|improve this answer
why iOS6? @property(nonatomic, readwrite, retain) UIView *backgroundView NS_AVAILABLE_IOS(3_2); // the background view will be automatically resized to track the size of the table view. this will be placed as a subview of the table view behind all cells and headers/footers. default may be non-nil for some devices. –  zakhej Sep 29 '12 at 19:57
Yes, I know. But the other solution that is mentioned here is not working on iOS6 and this solution was buggy on < 4 I think. I tried it before, but it did not work. Don't know when this exactly was fixed tho. –  bitboxer Sep 30 '12 at 0:04
add comment

If your class is a UIViewController subclass then you can do it like this:

[self.view setBackgroundColor:
     [UIColor colorWithPatternImage:
      [UIImage imageWithContentsOfFile:
       [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
share|improve this answer
Thanks, but that's actually the crux of my question. It is not a UIViewController - it is a UITableViewController. –  hookjd Nov 30 '09 at 17:30
then you should follwo that tutorial..... –  ByteSlick Dec 1 '09 at 4:10
what tutorial are you referring to? –  hookjd Dec 1 '09 at 5:36
add comment
UIImageView *backgroundView = 
backgroundView.frame = CGRectMake(0, 
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
[self.navigationController.view insertSubview:backgroundView atIndex:0];
[backgroundView release];
self.tableView.backgroundColor = [UIColor clearColor];

As Gorm said

only need to do it once, at the top level of the UINavigationController

share|improve this answer
add comment

The answer given my Madhup is the correct answer. UITableViewController is a subclass of UIViewController, so adding that to your UITableViewController's viewDidLoad method works great.

share|improve this answer
add comment

As of iOS 3.2, -[UITableView setBackgroundView:] exists, which may be easier than some of the other proposed solutions going forward.

share|improve this answer
add comment

Your Answer


