Adding background for window is not working

北城余情 提交于 2019-12-13 06:18:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!