我正在开发具有通用 UI 元素的 iOs 应用程序 - 所有场景的页眉(带有自定义按钮)、背景图像和页脚。是否可以使用具有通用元素的 Storyboard设计一个模板场景/ View ,并将其用于所有其他场景/ViewControllers 作为基础?在其他场景中,只需将内容添加到空闲位置(图像、表格...)。
我在考虑使用硬编码元素的通用自定义 UIViewController 父类(super class),但使用 Storyboard设计 UI 更容易。
应用程序必须与 iOs 5.0 兼容
最佳答案
选项包括:
使用自定义容器 View Controller 。将您的常用控件放在该 Controller 上,然后对您的 subview 使用 View Controller 包含。有关详细信息,请参阅
WWDC 2011 - 102 - Implementing UIViewController Containment视频
Implementing Custom View Controller在UIViewController 类引用
Creating Custom Container View Controllers在UIViewController 编程指南
定义一个
UIViewController
子类,以编程方式创建通用图形元素,然后从该子类继承所有其他 View Controller 。使用
UIAppearance
协议(protocol)来定义控件的通用外观。见:
就个人而言,我会将 UIAppearance
与其他两种方法之一结合使用。我倾向于自定义容器 Controller ,但是你失去了执行简单模式和推送 segues 的能力(我定义了一个自定义 segue 类型,它在 child 之间进行 segueing),所以我可以理解为什么你宁愿使用共享 UIViewController
子类。
关于ios - UI 模板 View - iOs 应用程序所有场景中的通用 UI 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15934987/