如何在InterfaceBuilder中显示自定义UIView? [英] How do you display custom UIViews in InterfaceBuilder?

查看:90
本文介绍了如何在InterfaceBuilder中显示自定义UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎喜欢设计实现自己的 -drawRect的新 UIViews UIControls 方法。这对我很有用,特别是在 Interface Builder 中使用 UIViews 编写时。

I seem to enjoy designing new UIViews and UIControls that implement their own -drawRect: method. This work well for me, especially when composed using UIViews in Interface Builder.

但是在Interface Builder中编写它们很烦人,因为它们只是显示为无聊的普通矩形。

But composing them in Interface Builder is annoying because they just show up as boring plain rectangles.

如果视图实际上将自己呈现为内置控件,那将会很棒执行。

It would be great if the views would actually render themselves as the built-in controls do.

我有什么方法可以构建我的项目,以便Interface Builder能够呈现我的自定义视图吗?

Is there any way I can structure my project so that Interface Builder will render my custom views?

推荐答案

为此,您实际上必须为使用自定义类的Interface Builder创建一个插件。一旦创建并安装了插件,您就可以将类的实例(视图)拖放到另一个窗口/视图/任何其他控件上。要开始创建IB插件,请参阅 Interface Builder插件编程指南。另外,我建议看一下Aaron Hillegass的书, Mac OS X的Cocoa编程 的。除了写得很好且易于理解之外,它还有一章介绍如何创建自己的IB调色板控件。

In order to do this, you actually have to create a plug-in for Interface Builder that uses your custom class. Once you create and install your plug-in, you will be able to drag and drop instances of your class (your view) onto another window/view/whatever just like any other control. To get started with creating IB Plug-Ins, please see the Interface Builder Plug-In Programming Guide. Also, I recommend taking a look at Aaron Hillegass's book, Cocoa Programming for Mac OS X. As well as being very well written and easy to understand, it has a chapter on creating your own IB Palette controls.

这篇关于如何在InterfaceBuilder中显示自定义UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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