如何在 XCode 4.1 中创建自定义的可重用 UIControl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7240411/
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
How to create custom reusable UIControls in XCode 4.1
提问by Pedro Borges
I want to create a custom UIProperty Control that is not more than a UILabel and a UITextField grouped together and add it to IB's Custom Objects list to reuse in other Nibs. I found a lot of documentation and everything points to creating a Xcode or IB plugin project, but everything refers to Xcode 3.x and there are no parallels in many spots. Anyone cares to help?
我想创建一个自定义 UIProperty 控件,它不超过一个 UILabel 和一个 UITextField 组合在一起,并将其添加到 IB 的自定义对象列表中以在其他 Nib 中重用。我找到了很多文档,所有内容都指向创建 Xcode 或 IB 插件项目,但所有内容都指的是 Xcode 3.x,并且在许多地方没有相似之处。有人愿意帮忙吗?
Thank you in advance
先感谢您
采纳答案by chown
Unfortunately, it's not easy, if even possible at all. Unlike Xcode 3, in XCode 4, Apple has pretty much eliminated this feature. They now say you must create the class manually first and then associate the controller object using Interface Builder.
不幸的是,这并不容易,甚至根本不可能。与 Xcode 3 不同,在 XCode 4 中,Apple 几乎消除了此功能。他们现在说您必须首先手动创建类,然后使用 Interface Builder 关联控制器对象。
InterfaceBuilder Docsexplain how to do it now in Xcode 4 using a custom object.
InterfaceBuilder Docs解释了如何使用自定义对象在 Xcode 4 中执行此操作。
And from the xcode 4 transition guide:
After adding the source file templates to your project, drag a custom view object from the library into the nib file. After adding the custom view to your nib, select the custom view and assign the correct class to it in the class field under Custom Class in the Identity inspector
并且来自xcode 4 转换指南:
将源文件模板添加到您的项目后,将自定义视图对象从库中拖到 nib 文件中。将自定义视图添加到您的笔尖后,选择自定义视图并在身份检查器中自定义类下的类字段中为其分配正确的类
Some more resources:
更多资源:
iphone-creating-custom-objects-for-interface-builder
iphone-creating-custom-objects-for-interface-builder
回答by Kenny Winker
Xcode 4 doesn't do plugins.
Xcode 4 不做插件。
Creating something that will be customizable in IB doesn't seem to be possible at this point. I think the strategy being used by and large is to avoid IB and do it all in code (e.g. most everything on cocoacontrols.com).
在 IB 中创建可定制的东西在这一点上似乎是不可能的。我认为主要使用的策略是避免 IB 并在代码中完成所有操作(例如 cocoacontrols.com 上的大部分内容)。