我想要一张图像占据整个导航栏。这是基于导航的应用程序附带的导航。它与随附的 UITableView 一起出现在 RootViewController 上。我已经看过一些例子来说明它是如何工作的。
设置导航栏标题:
UIImage *image = [UIImage imageNamed:@"TableviewCellLightBlue.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar.topItem setTitleView:imageView];
问题在于它只覆盖了标题而不是整个导航栏。
还有这个帖子:http://discussions.apple.com/message.jspa?messageID=9254241#9254241 。最后,该解决方案似乎使用了一个选项卡栏,但我没有使用它。设置导航栏背景有那么复杂吗?还有其他更简单的技术吗?
我希望有一个导航背景,并且仍然能够使用标题文本。
最佳答案
就您而言,this solution found in another answer效果很好。
将“CustomImage”类别添加到 UINavigationBar 后, 然后你可以调用:
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"yourNavBarBackground.png"];
[navBar setBackgroundImage:image];
此代码应该放在方法中
- (void)viewWillAppear:(BOOL)animated
您想要在其中拥有自定义图像的 View Controller 。 而且,在这种情况下,您最好调用:
[navBar clearBackgroundImage]; // Clear any previously added background image
setBackgroundImage之前(否则会添加多次...)
关于iphone - 将图像添加到导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1553118/