我想为我的应用放置一张无论如何都不会移动的绝对背景图片。
我希望看起来好像我的 segues 只是将 destinationViewController
的 View 移动到这个背景上,就像它是一页一样。
我看过这个答案,set background image for entire iPhone / iPad app ,但如前所述,colorWithPatternImage
会占用内存。
我想要一个 Objective-C 和 Swift 的答案。
谢谢
最佳答案
最简单的方法是将 UIImageView
添加到您的根窗口,并确保所有其他 View 都具有透明背景;
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;
}
关于ios - 为整个应用设置绝对背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35544720/