Set background image for entire iPhone / iPad app

I have one image that I want as a background for my application, no matter what management object they are on: how to do it?

+59
objective-c iphone ipad
Feb 06 '11 at 19:14
source share
8 answers

Here you set the background for the image:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]; 



Edit: To write what Felixis said (and thanks to Manny), do this in your delegate:

 window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]; 

And in every view you want to have an image, do the following:

 self.view.backgroundColor = [UIColor clearColor]; 
+88
Feb 06 '11 at 19:55
source share

Depends on which interface you have. Tabs? Navigation system? But the general answer is: add a UIImageView to your UIWindow before / below your main view. Then make each view processed by your main view controller a transparent background. It is difficult to give more specific advice without knowing whether you are using IB or not, or what your hierarchy of views looks like.

+8
Feb 06 '11 at 19:45
source share

In my application, I set the default background color. Perhaps you can do this with a background image:

1: Set the background color of your UIWindow to AppDelegate:

 window.backgroundColor = [UIColor myBackgroundGray]; // own Category 

2: And now make all other views transparent:

 self.view.backgroundColor = [UIColor clearColor]; // = transparent 
+7
Feb 06 2018-11-11T00:
source share

In AppDelegate in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

Add this line:

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

After you just need to set the viewing backgrounds to [UIColor clearColor];

+7
Dec 12 '12 at 12:24
source share

I'm not sure about the performance, but I had to do something, and in the end I used UIImageView, which works well (in C #, but works the same in obj-c):

 //Add the view controller first, to ensure proper order of views later. Window.RootViewController = new UIViewController(); //create backdrop image view var imageView = new UIImageView(Window.Bounds); imageView.Image = UIImage.FromBundle("backdrop.jpg"); //insert into window. Window.InsertSubview(imageView, 0); 

This does not handle orientation changes, but in my case it allowed me to add motion effects to the background (like parallax).

+3
May 30 '14 at 11:47
source share

Your background is a property of any object inherited from view. For example, shortcuts, buttons, controllers, and the application window have a background. If you want it to be completely bg for the whole application, you have to go up the path in your controllers to find the very "top" (bottom) view and set its background as the desired image.

+2
Jul 19 '11 at 18:28
source share

I usually use this function to avoid matches with the navigation bar on the iphone.

 -(void)setImageBackground:(NSString*)imageName{ UINavigationController* navigationController = [self navigationController]; float height = navigationController.toolbar.frame.size.height; CGSize size = self.view.frame.size; size.height = size.height; UIGraphicsBeginImageContext(size); CGRect bounds = self.view.bounds; bounds.origin.y = bounds.origin.y + height; bounds.size.height = bounds.size.height-height; [[UIImage imageNamed:imageName] drawInRect:bounds]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.view.backgroundColor = [UIColor colorWithPatternImage:image]; } 
0
Jun 26 '15 at 0:45
source share

just call it assignbackground in viewDidLoad

 override func viewDidLoad() { assignbackground() } func assignbackground(){ let background = UIImage(named: "background") var imageview : UIImageView! imageview = UIImageView(frame: view.bounds) imageview.contentMode = UIViewContentMode.ScaleAspectFill imageview.clipsToBounds = true imageview.image = background imageview.center = view.center view.addSubview(imageview) self.view.sendSubviewToBack(imageview) } 
0
Jun 12 '16 at 9:25
source share



All Articles