开发者

UIView or UIViewController for custom View

What is the best way to create a custom UIView that I can consume in Interface Builder?

  1. Create a custom UIView in Interface Builder and inherit from UIView in a code file, then somehow use it in another UIView ala like a control. (How do I do this?)

  2. C开发者_开发问答reate a custom UIView in Interface Builder and have a custom UIViewController wire it up. In my main ViewController, place the new view.

Basically, I am trying to create a reusable display view and would like a quick way to change it across all my instances with minimal effort. I already have laid out my XIB in Interface Builder.


The best is the 1st way. And don't forget to place IBOutlet keyword before class member, that you want to see in Interface Builder.

@interface MyViewController : UIViewController {
    IBOutlet UILabel *m_MyLabel;
}
....


You'll want to do (1). Presumably you've got an existing IB file in which you'd like to place the custom UIView subclass? In that case, go to that file, drag out a UIView, and then in the "Application Identity" tab of the inspector (4th tab) set the Class to your custom class (as defined in code).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜