添加窗口背景不起作用

时间:2013-09-20 04:30:15

标签: ios objective-c ios7

我有这个代码在XCode 4 / iOS 6上运行得很好,可以在窗口上添加背景图像:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]];
    return YES;

}

但今天,当我尝试将其放入XCode 5并尝试为iOS 7构建应用程序时,它已不再适用了。从XCode 4到XCode 5有什么变化吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试在您的窗口中添加控制器:

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;

确保图片扩展名包含在您的代码中,并且还导入到xcode项目中

此外,如果您在视网膜显示设备上进行部署,图像需要在名称之后和扩展名之前包含@ 2x,如下所示:

bgleft@2x.png