Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding background to entire UISplitViewController

Hey I want to add a background image to my UISplitViewController that spans the entire iPad screen and is visible underneath both my master and detail views.

I've tried this a number of different ways and have yet to be successful. If I place it in the splitView.view it just overlays on top of everything in both sub-view controllers. If I place it in the master view controller I can do things normally there (place a UITableView on top of it, etc), but it then covers everything in the detail view controller. Another route I tried was to place my background image in it's own view controller the put the entire split view controller inside that view controller, but no matter what I set the alpha of my split view controller the background is still black.

If someone could point me towards getting this working it would be awesome, thanks!

like image 678
Evan Davis Avatar asked Aug 17 '11 14:08

Evan Davis


2 Answers

Got it working!

First follow along with Apple's example of setting up a UISplitViewController programmatically here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/iPadControllers/iPadControllers.html

then add in this line before adding the VC to the window:

splitVC.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];
like image 112
Evan Davis Avatar answered Nov 20 '22 21:11

Evan Davis


I just came across this problem and the solution I've used is to put the background image in the split view controllers view and then send it to the back. Then it appears behind all the other content and as long as the master and detail views have a clear background color you can then see the background image.

So if self is a subclass of UISplitViewController and imgView is a UIImageView that contains the background image then I just added this at the end of the viewDidLoad() (making sure it was after I had assigned view controllers to the split view controller)

    self.view.addSubview(imgView)
    self.view.sendSubviewToBack(imgView)
like image 2
leafcutter Avatar answered Nov 20 '22 21:11

leafcutter