iPhone - Setting background on UITableViewController

I know it's been a long time, but just for the record.. I Think I found a better solution using UITableView.backgroundView:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lisbon.png"]];

self.tableView.backgroundView = imageView;
[imageView release];

I tried with an image size of 320x480 on iPhone, and works perfect (I have tried with .jpg also).


(This is basically the same as Hans Espen's solution above, but uses convenience methods for brevity)

Put this in your -[UITableViewControllerSubclass viewDidLoad] method:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern.png"]];

There's no point in avoiding a couple of autoreleases in a viewDidLoad method, since it only gets called rarely (when the view actually loads) and will therefore have negligible impact on performance.

N.B. You should always use PNG images on the iPhone, not JPEG or any other format.


Actually, I got it working! :)

NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
self.tableView.backgroundColor = backgroundColor; 
[backgroundColor release];

For Swift use this,

self.tableView.backgroundView = UIImageView(image: UIImage(named: "backgroundImage.png"))