Custom Control equivalent in XCode/MonoMac

旧时模样 提交于 2019-12-06 10:26:00

If you just want a group of standard controls, then you may want a standalone view NIB/XIB. Then you'd load that NIB each time you want to instantiate that group, get the top-level view from it, and insert that view into some other view hierarchy. You'd use an NSViewController (or a custom subclass) to own and load that NIB.

You can also add a free-standing view to a NIB that already contains, say, a window. The NIB's owner (often an instance of NSWindowController or a subclass) would have an outlet to refer to that free-standing view hierarchy. Your code could then use that view hierarchy at will, inserting it into the window's view hierarchy at an appropriate place.

You don't typically use a custom view class just to group standard controls. You only make a view subclass to make a non-standard view, one that draws in a custom manner or provides a different manipulation technique.

This worked for me:

  1. Drop a "Custom View" onto your window (do NOT rename the Class in identity inspector).

  2. Make an outlet for the Custom View in your window's controller called 'CustomView'.

  3. In your window controllers awakeFromNib method add the following code

    this.CustomView.AddSubview(new YourCustomViewController().View);

Note: other answers to this question assume your view has no XIB, and thus shows empty because it is not loaded properly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!