问题描述
我想要一张图片来占据所有导航栏。这是基于导航的应用程序附带的导航。它出现在RootViewController上,附带UITableView。我已经看到了一些如何工作的例子。
I'd like an image to take up all of a navigation bar. This is the navigation that comes with a navigation based app. It appears on the RootViewController with the accompanying UITableView. I've seen some examples of how this might work.
设置导航栏标题:
UIImage *image = [UIImage imageNamed:@"TableviewCellLightBlue.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar.topItem setTitleView:imageView];
问题在于它只涵盖标题而不是整个导航栏。
The problem there is it only covers the title rather than the entire navigation bar.
还有这个帖子:。接近最后,该解决方案看起来使用了一个我不使用的标签栏。设置导航栏背景是否复杂?还有其他一些更简单的技术吗?
There is also this thread: http://discussions.apple.com/message.jspa?messageID=9254241#9254241. Towards the end, the solution looks to use a tab bar, which I'm not using. It is that complicated to set a navigation bar background? Is there some other simpler technique?
我想有一个导航背景,仍然可以使用标题文字。
I'd like to have a background for the navigation and still be able to use title text.
推荐答案
在您的情况下,会很好。
In your case, this solution found in another answer would work well.
将CustomImage类别添加到UINavigationBar,
即可然后只需致电:
With the "CustomImage" category added to UINavigationBar,you can then just call:
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"yourNavBarBackground.png"];
[navBar setBackgroundImage:image];
此代码应采用方法
- (void)viewWillAppear:(BOOL)animated
您想要拥有自定义图像的视图控制器。
而且,在这种情况下你最好打电话:
of the view controller where you want to have the custom image.And, in that case you should better call:
[navBar clearBackgroundImage]; // Clear any previously added background image
(否则会多次添加... )
before setBackgroundImage (otherwise it will be added multiple times...)
这篇关于将图像添加到导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!