ios标签控制器怎么用_带故事板的iOS标签栏控制器

ios标签控制器怎么用

In this tutorial we’ll look into another type of view controller namely Tab Bar Controller. At the same time we’ll give the Storyboards a more closer look.

在本教程中,我们将研究另一种视图控制器,即Tab Bar Controller 。 同时,我们将使分镜脚本更仔细地观察。

总览 (Overview)

The UITabBar component is typically located at the bottom of the screen. It consists of an array of tabs that consists of a title and optional image. This component is useful when the user wants to go to different view screen depending on the Tab Bar item he pressed.

UITabBar组件通常位于屏幕底部。 它由一系列选项卡组成,这些选项卡由标题和可选图像组成。 当用户希望根据他按下的选项卡栏项目进入不同的视图屏幕时,此组件很有用。

Storyboards gives us the power to visually describe and present the flow of the application. It shows the components of each screen and how the screens are connected to each other. A ViewController is officially known as scene. We’ll use both the terms interchangeably. The arrow pointing from the left to the scene indicates the initial scene/view controller that’s launched.

故事板使我们能够直观地描述和呈现应用程序的流程。 它显示了每个屏幕的组件以及屏幕之间的连接方式。 ViewController正式称为scene 。 我们将两个术语互换使用。 从左侧指向场景的箭头表示启动的初始场景/视图控制器。

Storyboards describe the transitions from one screen to another using “segues“. Segues are analogous to intents in Android. We’ll discuss it at length in a later tutorial. For now all you need to know is that segues are used for transitions and passing the data from one scene to another.

故事板使用“ segues ”描述了从一个屏幕到另一个屏幕的过渡。 Segues类似于Android中的意图 。 我们将在以后的教程中详细讨论它。 现在,您只需要知道segue是用于过渡并将数据从一个场景传递到另一个场景的。

In this tutorial we’ll unleash the power of Storyboards to develop a basic TabBarController Application.
Start with creating a new Project(Choose Objective-C or Swift. It doesn’t matter. We aren’t going to modify the code anyways.)

在本教程中,我们将释放故事板的功能来开发基本的TabBarController应用程序。
从创建一个新项目开始(选择Objective-C或Swift。没关系。无论如何,我们都不会修改代码。)

Go to the Main.storyboard. Click the empty view controller and delete it. Now search for tab bar controller in the bottom right panel and drag it to the storyboard. The scene consists of a tab bar controller and two content views that are linked by segues. When you drag it to the storyboard, an image like the one given below would be seen.

转到Main.storyboard 。 单击空的视图控制器并将其删除。 现在,在右下方面板中搜索选项卡栏控制器,并将其拖到情节提要中。 该场景包含一个标签栏控制器和两个通过segue链接的内容视图。 当您将其拖到情节提要板上时,将看到类似于下面给出的图像。

The Tab Bar Controller consists of two bar items at the bottom. One for each of the content views.
Build the project now. You’ll get a runtime ERROR! The log console would show this:

标签栏控制器在底部由两个栏项目组成。 每个内容视图一个。
现在构建项目。 您将获得运行时错误! 日志控制台将显示以下内容:

Failed to instantiate the default view controller for UIMainStoryboardFile ‘Main’ – perhaps the designated entry point is not set?

无法实例化UIMainStoryboardFile'Main'的默认视图控制器-可能未设置指定的入口点?

Note: The storyboard is missing the arrow at the beginning of the scene that was there before.
Click the tab bar controller and go to the Attributes option in the utilities panel. The “Is Initial View controller is unchecked. Check it as shown in the image below:

注意:情节提要板缺少之前场景的开始处的箭头。
单击选项卡栏控制器,然后转到实用程序面板中的“属性”选项。 未选中“是初始视图控制器”。 如下图所示检查它:

Build the project and notice that it’s working fine.

生成项目,并注意它运行良好。

The Tab Bar Controller comes pre-configured with two additional view controllers, one for each tab. The relationship between the Tab Bar Controller and the views is shown by a segue. We’ll add two new ViewControllers and add them to the Tab Bar Controller as well. Following image shows how this is done.

选项卡栏控制器预先配置了两个附加的视图控制器,每个选项卡一个。 标签栏控制器和视图之间的关系由segue显示。 我们将添加两个新的ViewController,并将它们也添加到Tab Bar Controller。 下图显示了此操作的完成方式。

The above image shows how a few shifting of elements in the storyboard gives it a complete new look.

上图显示了情节提要中元素的一些移动如何使其具有全新的外观。

We’ve added a Tab Bar Item on each tab in the bottom of the ViewControllers. We can customise the text and icons from the attributes inspector. The respective tabs get automatically updated in the Tab Bar Controller scene. Do a control+click and drag the tab bar controller to the View Controllers we’ve added.

我们在ViewControllers底部的每个选项卡上添加了一个选项卡栏项。 我们可以从属性检查器中自定义文本和图标。 各个选项卡在“选项卡栏控制器”场景中自动更新。 按住Control键并单击,然后将选项卡栏控制器拖动到我们添加的“视图控制器”中。

Choose the relationship segue. This adds the View Controller to the array of tabs in the Tab Bar Controller. Let’s add Labels and change the background colour of each view controller. The storyboard should look something similar to the image given below.

选择关系序列。 这会将视图控制器添加到选项卡栏控制器中的选项卡阵列。 让我们添加标签并更改每个视图控制器的背景色。 情节提要的外观应类似于下面给出的图像。

The output of the application in action is given below.

实际应用程序的输出如下。

This brings an end to this tutorial. We’ve just played around with the UI in Storyboards to develop a basic application with four tabs. We’ll discuss more on segues in later tutorials.

本教程到此结束。 我们刚刚使用了Storyboards中的UI来开发具有四个选项卡的基本应用程序。 我们将在以后的教程中讨论更多关于segue的信息。

翻译自: https://www.journaldev.com/10590/ios-tab-bar-controller-with-storyboards

ios标签控制器怎么用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值