Set the background image for the entire iOS application

I am trying to set a background image for the entire application, following these guidelines: set a background image for the entire iPhone / iPad application

But in iOS 7 (I donโ€™t know about other versions) this does not work at all. I created a simple repository so you can better understand what is going on. There are some glitches in the transitions.

When you click on a line in the first view, the second view is entered into the navigation controller, but there is a strange effect. It seems that the transparency of the lines played into this. Another problem is that when you return to the previous view controller, a subtle shadow appears on the view controller that pops out of the navigation stack. As I said, you can get what I mean by running a simple Xcode project.

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

Any ideas? I already tried to set a background image for each controller, but this is not what I want, because in this way the image โ€œoverlapsโ€ the previous background image and is not the desired effect.

I hope I have a good explanation.

EDIT 1

The problem seems to be due to the way iOS 7 controls the transitions between the two view controllers. You are in the second view controller and trying to move to the previous controller using swipe gestures, you can see that as you start the gesture, the first controller appears under the second controller (the controller that you see), and since UITableViewCell have transparent background, you already see the first controller. In fact, I am afraid that there is no solution. What a pity that I cannot have a fixed background image without setting a background image on each controller.

enter image description here

+6
source share
7 answers

I had a requirement in the application for the iPhone to set the background image of the page based on user settings. The way I dealt with this was to add a UIImageView with a background image as a UIImageView view, for example:

 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 code snippet to the viewDidLoad both view controllers. I also added the following line of code in the same method -

 self.tableView.opaque = NO; 

I commented on the code in didFinishLaunchingWithOptions where you set the background color. With these changes, artifacts are displayed when navigating between dispatchers. I tested with the iPhone Retina (3.5-inch) as well as the iPhone Retina (4-inch) simulator.

The reason artifacts are visible when navigating a ViewController in a storyboard requires some research. My suggestion may or may not work for your requirements, but you can try this as a solution.

PS This method requires some settings for auto-detection restrictions.

+7
source

You just need to write only one line in
appdelegate.m file applicationdidFinishLaunchingWithOptions: method

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

and place below the line on each screen the viewDidLoad method

 [self.view setBackgroundColor:[UIColor clearColor]]; 
+4
source

I have not found a way to deliver this globally. However, you will probably find this useful for static / fixed images (instead of the moving images you get when setting the backgroundColor property). Use the backgroundView property for each screen.

 self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]]; 

I did this myself by creating a UtilTableViewController that does all the themes and user things I need to make this code, and then subclass all of my views. This is not a globally configured image, but I only need to install it once, and all my TableViews will use it.

+2
source

Put this code in your appdelegate.m applicationDidFinishLaunching file.

 UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController]; windowBackground=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background_window.png"]]; windowBackground.frame=CGRectMake(0, 0, 320, 568); [window addSubview:windowBackground]; [windowBackground release]; window.frame = CGRectMake(0, 0, window.frame.size.width,568); [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; 

Add this code to each viewController viewDidLoad method.

 self.view.backgroundColor = [UIColor clearColor]; 
+1
source

Late post ...

If you use a navigation controller, you can try overriding the โ€œGetโ€ part of the TopViewController to automatically configure the BackGroundColor to your image. In applications, we use Xamarin, which converts from C # to the target C for us (not sure about the specific syntax). In C #, it will look something like this in your NavigationController class.

  public override UIViewController TopViewController { get { if (base.TopViewController.View.BackgroundColor != "Your Image") { base.TopViewController.View.BackgroundColor = "Your Image"; } return base.TopViewController; } } 
+1
source

Write this code to the application (BOOL): (UIApplication *) application doneFinishLaunchingWithOptions: (NSDictionary *) start method

  UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"YourImageName.png"]]; self.window.backgroundColor = background; 
0
source

you can set the background image using the code below ... wew can put this code in the viewdidload method in the viewcontroller.m file

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

0
source

Source: https://habr.com/ru/post/959202/


All Articles