导航项标题视图 - 所有推送的视图控制器都相同 [英] Navigation item title view - same for all pushed view controllers

查看:41
本文介绍了导航项标题视图 - 所有推送的视图控制器都相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让所有推送的视图控制器的导航项标题视图保持相同?

How can you keep navigation item title view same for all pushed view controllers?

例如我想将标题视图设置为所有屏幕都应该可见的徽标.

E.g. I'd like to set title view to a logo that should be visible for all screens.

UIImage *logoImage = [UIImage imageNamed:@"navigation-bar-logo"];
UIImageView *titleLogo = [[UIImageView alloc] initWithImage:logoImage];
self.navigationItem.titleView = titleLogo;

如果我为每个视图控制器单独设置它,iOS7 导航栏动画看起来很奇怪.

If I set it for each view controller individually, it looks strange with the iOS7 navigation bar animation.

推荐答案

如果你想显示一个导航项的标题视图 - 所有推送的视图控制器都一样

If you want to show a Navigation item title view - same for all pushed view controllers

  • 将 ViewController 设为 ParentViewController 和所有其他ViewController 作为那个的孩子.那么无论你在 ParentVC 中做什么设计,它都会反映在 Child VC 中.

下面是例子.在 appDelegate 类中,

Below is the example . In appDelegate Class,

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[WARootViewController alloc]init]];
self.window.rootViewController = nav;

在 ViewController 中,设置 imageView Frame(可选,您可以提供您想要的)和 Image Name(如果 logoImage 提供 NULL 内存,请提及扩展名).

In the ViewController ,Set the imageView Frame(optional,You can give your desired) and Image Name(mention the extension if logoImage is giving NULL memory).

    UIImage *logoImage = [UIImage imageNamed:@"navigation-bar-logo.jpg"];
UIImageView *titleLogo = [[UIImageView alloc] initWithImage:logoImage];
titleLogo.frame = CGRectMake(0, 0, 50, 30);
self.navigationItem.titleView = titleLogo;

  • 将其余的 ViewControllers 作为 WARootViewControllers 的子级

    • Make Rest of the ViewControllers as child of WARootViewControllers

      #import "WARootViewController.h"
      @interface WAFirstViewController : WARootViewController
      
      #import "WARootViewController.h"
      @interface WASecondViewController : WARootViewController
      

    • 这篇关于导航项标题视图 - 所有推送的视图控制器都相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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