设置“默认” UIViewController背景图片?

发布于 2024-09-16 06:19:51 字数 481 浏览 2 评论 0原文

基本上我的整个 iPhone 应用程序都有相同的背景图像。

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

所以我想知道是否有任何方法可以向我的所有 UIViewController 添加“默认”背景图像?

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

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

有没有简单的方法可以通过编程来完成此操作?

谢谢 汤姆

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

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

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

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

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?

Thanks
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尝蛊 2024-09-23 06:19:51

如果您将 UIImageView 添加到应用程序委托中的 UIWindow (确保它位于根视图下方),然后确保所有 VC 都是不透明的,这应该可以解决您的问题。

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文