如何以编程方式创建控制器和 UIView 而不使用界面构建器? [英] How to create the controller and the UIView programmatically and not use the interface builder?

查看:21
本文介绍了如何以编程方式创建控制器和 UIView 而不使用界面构建器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习一些有关在 iOS 上创建视图和视图控制器的基础知识.我遇到的所有示例和文档都使用 Interface Builder 和 NIB 文件来创建 UIViewControllers 和 UIViews.如何以编程方式创建控制器和 UIView 而不使用界面构建器?

I am trying to learn some of the basics about creating views and view controllers on iOS. All the samples and documentation I've come across use the Interface Builder and NIB files to create UIViewControllers and UIViews. How to create the controller and the UIView programmatically and not use the interface builder?

推荐答案

你可以这样做,这是肯定的.但你应该在这里看到利弊;

You may do that, that's for sure. But you should see the pros and cons here;

你用代码创建和管理一切,好吗?

You create and manage everything in code, neat huh?

  • 这意味着,您将自己保留/释放所有内容.
  • 您将编写大量样板代码,只是为了创建具有不止一层组件层次结构的复杂视图.
  • 您不会看到可以更改的属性,而是需要查看每个组件的类参考文档.
  • 您需要大量使用像素值,我无法强调这个很多"最终会持续多久.

所以,考虑一下Interface Builder,将所有东西分开,然后根据需要绑定它们会更容易.随着应用程序的成熟,代码维护在后期阶段变得更加重要.

So, consider Interface Builder, it is easier to keep everything seperate, and then bind them as needed. Code maintenance is much more important in the later phases, as the app becomes mature.

两种方式我都经历过,我对 Interface Builder 的投票是 +1,并且仅在需要时覆盖内容.实际上,这不到 UI 开发时间的 5%.

I have been through both ways, and my vote is +1 for Interface Builder, and override stuff only when needed. That is in practice less than like 5% of your UI development time.

这篇关于如何以编程方式创建控制器和 UIView 而不使用界面构建器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆