设置整个应用程序的绝对背景

时间:2016-02-22 02:09:08

标签: ios objective-c swift uiviewcontroller

我想为我的应用程序放置一个绝对的背景图像,无论如何都不会移动。

我希望看起来好像我的segues只是将destinationViewController的视图移动到这个背景上,就像它是一页一样。

我已经看到了这个答案,set background image for entire iPhone / iPad app,但如上所述,colorWithPatternImage吞噬了记忆。

我想在Objective-C和Swift中找到答案。

由于

1 个答案:

答案 0 :(得分:1)

最简单的方法是在根窗口中添加UIImageView,并确保所有其他视图都具有透明背景;

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    let window=self.window!

    let backgroundView=UIImageView(frame: window.frame)

    backgroundView.image=UIImage(named: "Background.JPG")!

    window.addSubview(backgroundView)

    return true
}

或在Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

    UIWindow *window=application.windows.firstObject;
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:window.frame];

    imageView.image=[UIImage imageNamed:@"Background.jpg"];

    [window addSubview:imageView];
    return YES;
}