I have BackButton that inherits UIButton.
It doesn’t have a xib, is pretty simple and contains some layout logic which I omit.
Here is how I declared it:
[Register("BackButton")]
public class BackButton : UIButton
{
public BackButton (string text, EventHandler handler)
: base (UIButtonType.Custom)
{
TouchUpInside += handler;
SetTitle (text, UIControlState.Normal);
}
public BackButton(IntPtr handle) : base(handle) { }
}
If I use BackButton in another view’s xib, its underlying class is seen as BackButton:

However, when I create an instance from code, the underlying class is just UIButton:

This is frustrating because I’m trying to use UIAppearance for this class and I need it to be the right instance.
What’s the problem?
Turns out, I had to call the parameterless
UIButtonconstructor, and not the one I was calling.Removing
: base (UIButtonType.Custom)from constructor defnition was enough to make it work:In hindsight, this makes perfect sense because
UIButton(UIButtonType)constructor provided by MonoTouch actually calls[UIButton buttonWithType:]:There is no way, I presume, for
[UIButton buttonWithType:]to know about my custom view so it just creates aUIButton.