Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add background image to UITableViewController in Navigation based app

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.

like image 267
hookjd Avatar asked Nov 28 '09 21:11

hookjd


1 Answers

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).

like image 59
Gorm Avatar answered Nov 06 '22 12:11

Gorm