简体   繁体   English

将Interface Builder代码转换为Xcode

[英]Convert Interface Builder code to Xcode

Is it true that everything you do in Interface Builder can be done programmatically? 您在Interface Builder中执行的所有操作都可以通过编程方式完成吗? If your project uses Interface Builder to make the GUI, can that code be converted to native Xcode and inserted into the project? 如果您的项目使用Interface Builder来创建GUI,那么该代码是否可以转换为本机Xcode并插入到项目中?

It is true that anything you can do in Interface Builder you can do programatically. 确实,您可以在Interface Builder中执行的任何操作都可以以编程方式执行。 However, IB does not generate code, so there is not really anything to 'convert' to source code for your project. 但是,IB不生成代码,因此没有任何东西可以“转换”为您项目的源代码。

Interface Builder creates archived objects -- serialized instances of class instances -- and works directly from those. Interface Builder创建归档对象 - 类实例的序列化实例 - 并直接从这些对象开始工作。 While you can reuse your .xib files (which some people still insist on calling "nibs") in any number of projects, you should note that: 虽然您可以在任意数量的项目中重用您的.xib文件(有些人仍坚持调用“nibs”),但您应该注意:

  1. Your nib is already code: it's just very verbose and hard-to-read XML. 你的笔尖已经是代码了:它只是非常冗长且难以阅读的XML。 This XML contains the serialized (say "archived") instances. 此XML包含序列化(说“存档”)实例。
  2. You cannot "convert" your xib to Objective-C code, or at least Xcode does not provide a way to do this (and I don't know who would). 你不能将你的xib“转换”为Objective-C代码,或者至少Xcode没有提供这样做的方法(我不知道谁会这样做)。
  3. If you do not have the classes that the xib expects, you will run into errors using your xib. 如果你没有xib所期望的类,你将使用你的xib遇到错误。

I wrote a utility to convert .xib files to code. 我写了一个实用程序来将.xib文件转换为代码。 It's still experimental, but should do the majority of the grunt work converting to code: 它仍然是实验性的,但应该将大部分繁琐的工作转换为代码:

https://github.com/Raizlabs/Eject https://github.com/Raizlabs/Eject

You can try it out online: 你可以在网上试试看:

https://eject.herokuapp.com/ https://eject.herokuapp.com/

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

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