设置“默认" UIViewController背景图片? [英] set "default" UIViewController background image?

查看:285
本文介绍了设置“默认" UIViewController背景图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我在整个iphone应用程序中都有相同的背景图片.

Basically I've got the same background image throughout my entire iphone application.

我不使用XIB(讨厌的东西:p).

I don't use XIBs (nasty things :p).

所以我想知道是否有办法向所有UIViewControllers添加默认"背景图像?

So I was wondering if there was any way to add a "default" background image to all of my UIViewControllers?

我尝试子类化UIViewController并创建了类UIViewControllerWithDefaultBackground,但是将我的所有uiviewcontrollers切换为子类UIViewControllerWithDefaultBackground只会使我的应用程序崩溃.再加上一半的视图是UITableViewControllers ...但是我很高兴只需要更改2个类...:p

I tried subclassing UIViewController and created the class UIViewControllerWithDefaultBackground, but changing over all my uiviewcontrollers to subclass UIViewControllerWithDefaultBackground just crashes my app. Plus half of my views are UITableViewControllers... but I'd be happy just having to change 2 classes... :p

有什么办法吗?我只是不想将相同的3或4行代码复制并粘贴到我要启动的每个类中.另外,如果我想在任何时候进行编辑(取出导航栏并扩展视图,可以说),那么我将不得不更改所有不同的类.

Is there any way of doing this? I just don't want to have to copy and paste the same 3 or 4 lines of code into every single class I'm initiating. Plus, if I want to edit it at any point (take out the navigation bar and extend the view lets say) then I would have to change all my different classes.

没有简单的方法以编程方式执行此操作吗?

Is there no easy way to do this programatically?

谢谢 汤姆

推荐答案

如果在应用程序委托中将UIImageView添加到UIWindow中(确保其位于根视图下方),则请​​确保所有VC都是不透明的,这应该解决您的问题.

If you add a UIImageView to your UIWindow in your app delegate (make sure it's below the root view), then make sure all your VC's are opaque, that should solve your problem.

在IB中这样做会更容易,特别是如果您已经创建了MainWindow .xib(尽管为空白),则只需将图像拖放到UIWindow中即可.

This would be easier to do in IB, especially if you have a MainWindow .xib already created (albeit blank)--you just drag and drop the image into the UIWindow.

这篇关于设置“默认" UIViewController背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆