简体   繁体   中英

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. Create 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM