简体   繁体   English

iOS标签栏控制器,在控制器顶部添加导航按钮

[英]iOS tab bar controller adding a navigation button at the top of the controller

So I have a UITabBarController and it has three buttons on the bottom in my iOS app. 所以我有一个UITabBarController ,它在我的iOS应用程序的底部有三个按钮。 I want to add another set of buttons at the top but not quite sure on how to do this. 我想在顶部添加另一组按钮,但是不确定如何执行此操作。 I tried adding a UINavigationBar and a navigation button, and adding a view in to it, adding just the buttons, ect.... but to no avail. 我尝试添加UINavigationBar和导航按钮,并向其中添加视图,仅添加按钮,等等。。。但无济于事。 It won't let me add anything to the UITabBarController . 它不会让我向UITabBarController添加任何内容。 Is there a way to do this? 有没有办法做到这一点? Thank you very much. 非常感谢你。

故事板

To use the navigation bar you need a navigation controller. 要使用导航栏,您需要一个导航控制器。 Now depending on your needs your tab bar controller should be inside a navigation controller or the other way around. 现在,根据您的需要,选项卡栏控制器应位于导航控制器内部或相反。 If you want to be able to navigate away from the tab bar controller (have a screen without the tab bar) you should embed your tab bar controller into a navigation controller. 如果您希望能够离开标签栏控制器(屏幕没有标签栏)离开,则应将标签栏控制器嵌入导航控制器中。 If you only need the navigation bar for some tabs of the tab bar controller or you still want the tab bar to be visible all the time you should embed all (or just the ones than need a navigation bar) your root view controllers for each tab in navigation controllers. 如果您只需要标签栏控制器的某些标签的导航栏,或者您仍希望标签栏始终可见,则应为每个标签嵌入所有(或仅需要导航栏的标签)控制器在导航控制器中。 Finally if you do not need the navigation behaviour you could just put a regular view in the view controller that needs the bar at the top and some buttons in it and make them look the way you want. 最后,如果您不需要导航行为,则可以在视图控制器中放置一个常规视图,该视图的顶部需要条形图,并在其中包含一些按钮,并使它们看起来像您想要的样子。

You can embed a view controller in a navigation controller in a storyboard by selecting the view controller and the going to Edit->Embed in->Navigation controller. 您可以通过选择视图控制器,然后转到“编辑”->“嵌入”->“导航”控制器,将视图控制器嵌入到情节提要中的导航控制器中。

Select the Any Tabbar ViewController then above the Menu -> Editor -> Embed In -> Navigation Controller its select, if you get the Navigation Controller then if you add the Navigation Button at Top of the ViewController, example : 选择Any Tabbar ViewController,然后在菜单->编辑器->嵌入->导航控制器上方,选择它,如果您获得了导航控制器,则在ViewController顶部添加了导航按钮,例如:

在此处输入图片说明

the simplest way to that is to creat 3 buttons side by side and set their frame the way they divide the top of screen to 3 equals. 最简单的方法是并排创建3个按钮,并按照将屏幕顶部划分为3个相等的方式设置它们的框架。 it means u can create a tab bar with buttons manually. 这意味着您可以手动创建带有按钮的标签栏。 but there's another way. 但是还有另一种方式。 i think this answer would help u Positioning UITabBar at the top 我认为此答案将有助于u 将UITabBar定位在顶部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM