resedasue
resedasue

Reputation: 434

Fixed Background for iPhone app using Storyboard

Can't seem to find a way to fix a graphic - a light graphic that would remain static as the user navigates from scene to scene. Have been combing forums for a few days, but most answers point to MainWindow.xib, which isn't generated for a storyboard project. Would appreciate any advice.

Upvotes: 3

Views: 9145

Answers (4)

resedasue
resedasue

Reputation: 434

Here’s what I was able to cobble together thanks to advice from @Max. Like I said, very new to this, so if this code needs tuning please leave a comment so I don’t lead others astray.

Add the image to the app’s main window in the AppDelegate’s didFinishLaunchingWithOptions method :

UIImageView *myGraphic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myGraphic.png"]];
[self.window.rootViewController.view addSubview: myGraphic];
[self.window.rootViewController.view sendSubviewToBack: myGraphic];

Then, to make your views transparent so the background shows through - in your viewController class/es, add to viewDidLoad method:

self.view.backgroundColor = [UIColor clearColor];

(And note if you try to decrease the transparency through the alpha property for the view via the Attributes Inspector, it will make everything transparent on that view -buttons, etc - that’s why it needs to be done programmatically.)

Sure, it’s not thoroughly tested. But for now it’s working and it’s a thing of beauty. Thanks all.

Upvotes: 6

Matisse VerDuyn
Matisse VerDuyn

Reputation: 1138

If you're going to tackle this programmatically, within each view controller, set:

[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

in viewDidLoad

I'm sure some tweaking would allow you to apply this principle throughout the program from the app delegate, or by using a singleton.

Using this solution, though, you're still going to have to make some method call within each view controller where you want this style applied.

Upvotes: 0

Max
Max

Reputation: 16709

You can try to manually add UIImageView to your window and then set 0 background transparency for all other views.

Upvotes: 1

Sierra Alpha
Sierra Alpha

Reputation: 3727

One way to do it -- it may not be the best -- can be that you subclass a UIView, and set the UIView instance in all of your viewControllers in the storyboard an instance of your cutomized UIView class, which contains your graphic as a background.

Upvotes: 1

Related Questions