问题
I have this code which run very well on XCode 4 / iOS 6 to add background image on window :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]];
return YES;
}
but today, when I try to put it into XCode 5 and try to build an app for iOS 7, it's not working anymore. is there something changed from XCode 4 to XCode 5?
thank you.
回答1:
Try adding a controller to your window:
UIViewController *controller = [[UIViewController alloc] init];
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]]; // (the error may be here, where's the extension for the image? ".png" for example
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
return YES;
And make sure the images extension is included within your code, and is also imported into the xcode project
Also if you're deploying on a retina display device, the image needs to include @2x after the name and before the extension, like so:
bgleft@2x.png
来源:https://stackoverflow.com/questions/18908836/adding-background-for-window-is-not-working