ios .xib 文件和 .storyboard 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8436324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:48:20  来源:igfitidea点击:

What is the difference between a .xib file and a .storyboard?

iphoneiosios5xibxcode-storyboard

提问by George Sachpatzidis

Can someone explain in simple words the difference between .xib and .storyboard?

有人可以用简单的话解释 .xib 和 .storyboard 之间的区别吗?

采纳答案by Sagar Hatekar

Apple introduced the concept of "storyboarding"in iOS5 SDK to simplify and better manage screens in your app. You can still use the .xibway of development.

Apple"storyboarding"在 iOS5 SDK 中引入了 的概念,以简化和更好地管理应用程序中的屏幕。您仍然可以使用.xib开发方式。

Pre-storyboard, each UIViewControllerhad an associated .xibwith it. Storyboardachieves two things:

预故事板,每个UIViewController都有一个与之相关的.xibStoryboard实现两件事:

  1. .storyboardis essentially one single file for all your screens in the app and it shows the flow of the screens. You can add segues/transitions between screens, this way. So, this minimizes the boilerplate code required to manage multiple screens.

  2. Minimizes the overall number of files in an app.

  1. .storyboard本质上是应用程序中所有屏幕的一个文件,它显示了屏幕的流程。您可以通过segues这种方式在屏幕之间添加/transitions。因此,这最大限度地减少了管理多个屏幕所需的样板代码。

  2. 最大限度地减少应用程序中的文件总数。

You can avoid using Storyboardwhile creating a new project by leaving the "Use Storyboard" option unchecked.

您可以Storyboard通过不选中“使用故事板”选项来避免在创建新项目时使用。

You could refer this tutorialto get started.

您可以参考本教程开始。

回答by Nathanial Woolls

Yes, you can still create a Window-based application for iOS 5. If you use the "empty project" template, you will see that a window is created for you in the app delegate. From there you can add XIB files as normal, or a new storyboard.

是的,您仍然可以为 iOS 5 创建一个基于窗口的应用程序。如果您使用“空项目”模板,您将看到在应用程序委托中为您创建了一个窗口。从那里你可以像往常一样添加 XIB 文件,或者一个新的故事板。

I'm assuming you mean "storyboards" rather than "timeline". Storyboards allow you to map out, visually, all of the views in your applications and how they interrelate. If you are just starting out with storyboards, there's an introduction to storyboards in the WWDC 2011 videos here. The 2011 Stanford iOS courseon iTunes-U is also iOS 5-specific and covers storyboards and more.

我假设你的意思是“故事板”而不是“时间线”。故事板允许您直观地绘制应用程序中的所有视图以及它们如何相互关联。如果你是刚刚起步的故事板,有一个介绍故事板在WWDC 2011的视频在这里。iTunes-U 上的2011 年斯坦福 iOS 课程也是针对 iOS 5 的,涵盖故事板等。

回答by robertfiorentino

A storyboard is like a canvas where you put all your .xib files. You no longer have any .xibs, you just have View Controllers directly on your canvas.

故事板就像一个画布,您可以在其中放置所有 .xib 文件。你不再有任何 .xibs,你只有直接在你的画布上的视图控制器。

回答by mustafa

storyboard is a new feature available since the release of Xcode 4.2. It offers a complete new way for iOS developer to create and design user interface. Before the introduction of Storyboard, it's especially hard for beginner to create navigation (and tab) interface. Every interface is stored in a separate xib file. On top of it, you have to write code to link all interfaces together and describe how the navigation works.

With Storyboards, all screens are stored in a single file. This gives you a conceptual overview of the visual representation for the app and shows you how the screens are connected. Xcode provides a built-in editor to layout the Storyboards. You can define the transition (known as segues) between various screens simply using point and click. This doesn't mean you do not need to write code for the user interface. But Storyboards significantly reduce the amount of code you need to write.

故事板是自 Xcode 4.2 发布以来可用的新功能。它为 iOS 开发人员提供了一种全新的方式来创建和设计用户界面。在引入 Storyboard 之前,初学者创建导航(和选项卡)界面尤其困难。每个接口都存储在单独的 xib 文件中。最重要的是,您必须编写代码将所有界面链接在一起并描述导航的工作原理。

使用 Storyboards,所有屏幕都存储在一个文件中。这为您提供了应用程序视觉表示的概念概述,并向您展示了屏幕的连接方式。Xcode 提供了一个内置的编辑器来布局故事板。您只需使用点击即可定义各种屏幕之间的过渡(称为转场)。这并不意味着您不需要为用户界面编写代码。但是故事板显着减少了您需要编写的代码量。

Source: http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/

来源:http: //www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/

回答by Jitendra Gochhayat

XIB:

西博:

1) Xib files are used with a single UIView.

1) Xib 文件与单个 UIView 一起使用。

2)It's very difficult to implement complex auto-layouts in xib.

2)在xib中实现复杂的自动布局非常困难。

3)It's utilizes more memory as compared to storyboard and quiet slow.

3)与故事板相比,它使用更多的内存并且安静缓慢。

4) It is compatible from iOS5 and onwards

4) 兼容iOS5及以上

5) You can do localizations for different languages and countries using different XIBs .

5) 您可以使用不同的 XIB 为不同的语言和国家/地区进行本地化。

6) It's difficult to use same Xib to support multiple devices.

6) 很难使用同一个 Xib 来支持多个设备。

Storyboard

故事板

1)You can layout all your Scenes like View Controllers, Nav Controllers, TabBar Controllers, etc in a single storyboard.

1)您可以在单个故事板中布置所有场景,如视图控制器、导航控制器、TabBar 控制器等。

2)You can use Auto Layout easily that defines mathematical relationships between elements defining their position and sizing.

2)您可以轻松使用自动布局,它定义了元素之间的数学关系,定义了它们的位置和大小。

3)Usually fast and allocates less memory.

3)通常速度快,分配的内存较少。

4)It's not compatible prior to iOS 5 .

4) 它在 iOS 5 之前不兼容。

5)"Dynamic" and "Prototype" cells can be used easily.

5)“动态”和“原型”单元可以轻松使用。

6)Storyboards best to use for the apps with a small to medium amount of screens.

6)故事板最适合用于中小屏幕的应用程序。

The best Answer I have seen : Xib Vs Storyboard in iOS

我见过的最佳答案:iOS 中的 Xib 与故事板

回答by No_name_untilRecognised

XIB and Storyboard are used for creating interfaces for users.

XIB 和 Storyboard 用于为用户创建界面。

One important point is,xibs are used for creating a single view(it has single file owner at the top of the xib file), but in-case for viewcontroller, multiple screens can be added and its flow can also be monitored(it has separate file owners).

一个重要的一点是,xib 用于创建单个视图(它在 xib 文件的顶部具有单个文件所有者),但在视图控制器的情况下,可以添加多个屏幕并可以监控其流程(它有单独的文件所有者)。