开发者

UIView or UIViewController for custom View

开发者 https://www.devze.com 2022-12-27 10:44 出处:网络
What is the best way to create a custom UIView that I can consume in Interface Builder? Create a custom UIView in Interface Builder and inherit from UIView in a code file, then somehow use it in ano

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

精彩评论

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

关注公众号