【问题标题】:How to add Text Field and Images in Navigation Bar of Tab Bar?如何在标签栏的导航栏中添加文本字段和图像?
【发布时间】:2017-02-22 10:49:28
【问题描述】:

我想在标签栏控制器的导航栏上添加文本字段和搜索图标。请检查附件图片。

注意:这是主屏幕,如果用户单击任何菜单项,它将转到detailvc,因此我在homevc 上添加了一个导航控制器并将其隐藏。

我想在标签栏的导航栏显示搜索图标文本字段。我该怎么做?

【问题讨论】:

  • 这看起来像android - 你的意思是android开发吗?
  • 您可以使用自定义视图代替宽度和高度相同的导航栏。在此视图中,您可以设置任何您想要的内容。
  • @HannahLouisaCarney screenshort 来自 android,但我想要在 iOS 中相同。
  • @Jecky 当嵌入标签栏时,栏会自动出现。我可以这样设置标题:- [self.tabBarController setTitle:@"Title"];如何添加文本文件和图像视图?
  • @arpit 您可以创建自定义导航栏。查看视图并将文本字段和图像放在视图中。

标签: ios objective-c tabbar


【解决方案1】:

导航标题视图中设置带有左视图的文本字段

navigationItem.titleView = UITextField()

【讨论】:

    【解决方案2】:

    子类化导航栏

    @interface SearchNavigationBar : UINavigationBar

    -(void)layoutSubviews
    {
        [super layoutSubviews];
         UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"searchImage"] style:UIBarButtonItemStylePlain target:self action:@selector(searchPrompt:)];
         self.topItem.rightBarButtonItem = buttonItem;
    }
    

    将其添加为导航控制器的类

    并以这种方式获取对象

    UINavigationController *navBar = [[UINavigationController alloc] initWithNavigationBarClass:[SwitchAssessmentNavigationBar class] toolbarClass:nil];

    然后您可以在工具栏上调用自定义方法,例如触发主页面中的事件进行更改的委托

    【讨论】:

      【解决方案3】:

      导航栏中心的搜索栏:

      self.navigationItem.titleView = self.searchBarTop;
      

      导航栏左侧/右侧的搜索栏:

      UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
      self.navigationItem.rightBarButtonItem = searchBarItem;
      

      【讨论】:

        【解决方案4】:

        创建一个 UIView 自定义类来保存您的自定义搜索栏。 然后将该视图的实例添加到您的 navigationController 的视图中。

        [self.navigationController.view addSubview:yourCustomView];
        

        【讨论】:

          【解决方案5】:

          我必须添加自己的 UItabbar-Contrller 自定义自定义类

          【讨论】:

            猜你喜欢
            • 2018-02-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-07-21
            • 1970-01-01
            相关资源
            最近更新 更多