无法为 UINavigationController 设置背景图像 [英] Can't set a background image to UINavigationController

查看:36
本文介绍了无法为 UINavigationController 设置背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中添加了一张图片.奇怪的是,在文件系统上,它位于应用程序的根目录中,而在 XCode 的项目资源管理器中,我将它放在 /Images/navbar-bg.png 中.如何使其保持一致?

I've added an image to my project. Strangely, on the filesystem it is located in the root directory of the application, while in the project explorer within XCode I've put it in /Images/navbar-bg.png. How to make this consistent?

顺便说一下,我想将它作为背景图片添加到我的 UINavigationController 中.这是代码,但我看不到默认蓝色背景的变化:

By the way, I want o add it as background image to my UINavigationController. This is the code, but I see no changes from the default blue background:

// navigation
navigationController = [[UINavigationController alloc] initWithRootViewController:cardListViewController];
// ps hue: 37, 53, -5
navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"navbar-bg" ofType:@"png"]]];

self.window.rootViewController = navigationController;

我也试过 UIImage imageNamed 没有结果.我想以编程方式执行此操作,但此处未使用任何 xib.

I've also tried UIImage imageNamed with no results. I want to do it programmatically and I'm not using any xib here.

谢谢

推荐答案

您在 XCode 项目资源管理器中看到的那些黄色文件夹图标实际上并不代表文件夹;它们是 groups.当然,您可以将文件移出 Images 子文件夹以使其保持一致,但我认为您想要反其道而行之.

Those yellow-looking folder icons you see in XCode's project explorer don't actually represent folders; they are groups. You can, of course, move the file out of the Images subfolder to make it consistent, but I presume you want to do the reverse.

要将项目添加到您的项目并让它们保留其源文件夹名称,您必须创建文件夹引用".在添加文件..."对话框中,选择为任何添加的文件夹创建文件夹引用"单选按钮.你会得到一个蓝色的文件夹图标,而不是黄色的;该文件夹中的所有项目都将添加到您的项目中,并且只要您更改该文件夹的内容,构建的可执行文件就会与其内容匹配.

To add items to your project and have them retain their source folder name, you have to create 'folder references'. In the Add Files... dialog, choose the "Create folder references for any added folders" radio button. You'll get a blue folder icon instead of a yellow one; all items in that folder will get added to your project, and any time you change the contents of that folder, the built executable will match its contents.

...而且,你问了第二个问题...

... and, you asked a second question ...

在 iOS 5 中,要将图像添加到导航栏,请使用 UINavigationBar:setBackgroundImage.

In iOS 5, to add an image to a navigation bar, use UINavigationBar:setBackgroundImage.

这篇关于无法为 UINavigationController 设置背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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