How to use custom subclass of UIView in XIB editor using Monotouch?

I added a XIV based on a UIViewController to my solution and dragged UIViews into it. Now I want some of the views not to be a UIView , but a RoundedRectView (https://github.com/Krumelur/RoundedRectView) that inherits from UIView .

How to achieve this? I tried changing the class in Interface Builder but did nothing. Then I manually modified the designer.cs file, but this led to an error. Then I tried to change the fake ObjC code, but that also failed.

(I am using Xcode 4.2 and MD 2.8.6.4)

+6
source share
1 answer

Your view subclass requires at least two things:

  • Register Attribute

    [Register("MyView")]

    public class MyView : UIView {}

  • Constructor IntPtr

    public MyView(IntPtr handle) : base(handle) {}

Then you open the XIB in the interface builder, add a UIView and set your class in the Identity Inspector for the name that you passed to the Register attribute. When you plug it in, you will see that it is of the correct type.

Outlet with correct type

+8
source

Source: https://habr.com/ru/post/908797/


All Articles