Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background image for entire iOS app

I'm trying to set a background image for the entire app following this suggestions: set background image for entire iPhone / iPad app

But in iOS 7 (don't know about other versions) it doesn't work well at all. I've created a simple repository so you can understand better what's is going on. There are some glitches in the transitions.

When you tap on a row in the first view, the second view is pushed into the navigation controller but there's a weird effect. It seems that the rows transparency played into this. Also the other problem is when you turn back to the previous view controller there's a subtle shadow of the view controller that is popped from the navigation stack. As I stated before you can get what I mean by running the simple Xcode project.

Repo: https://github.com/socksz/FixedBackgroundImage

Any ideas? I've already tried to set the background image for each controller but it isn't what I want because in that way the image "overlaps" the previous background image and it's not the desired effect.

Hope I explained well.

EDIT 1

It seems that the problem occurs because of the way iOS 7 manages the transitions between two view controllers. In you are in the second view controller and try to turn to the previous controller with the swipe gesture you can see that as you begin the gesture the first controller appears below the second controller (the controller you're seeing) and, since the UITableViewCells have transparent backgrounds, you already see the first controller. Actually I'm afraid that there's not a solution. What a pity that I cannot have a fixed background image without setting the background image on each controller.

enter image description here

like image 788
Fred Collins Avatar asked Dec 02 '13 22:12

Fred Collins


2 Answers

I had a requirement in an iPhone app to set the background image of a page based on a user's preferences. The way I dealt with it was to add a UIImageView with the background image as a sub-view of the view, like so -

UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image"]];
bgImageView.frame = self.view.bounds;
[self.view addSubview:bgImageView];
[self.view sendSubviewToBack:bgImageView];

I cloned your Github repository and added the above piece of code in viewDidLoad of both the view controllers. I also added the following line of code in the same method -

self.tableView.opaque = NO;

I commented out the code in didFinishLaunchingWithOptions where you set the background color. With these changes, the artifacts while navigating between view controllers are gone. I tested with iPhone Retina (3.5-inch) as well as iPhone Retina (4-inch) simulators.

The reason why the artifacts are seen while navigating to and from the ViewController in the storyboard require some investigations. My suggestion may or may not work for your requirements, but, you can try this as a solution.

P.S. The method requires some tweaks to autolayout constraints.

like image 61
indyfromoz Avatar answered Oct 28 '22 14:10

indyfromoz


You Just have to write only one line in
appdelegate.m file's applicationdidFinishLaunchingWithOptions: method

[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"MainBackground.png"]]];

and put below line in every screen's viewDidLoad method

[self.view setBackgroundColor:[UIColor clearColor]];
like image 5
Haresh Ghatala Avatar answered Oct 28 '22 15:10

Haresh Ghatala