MonoTouch - how to override static UIView.layerCla

2019-07-26 09:36发布

问题:

I'm trying to port AUISelectiveBordersView to MonoTouch. It's basically a subclass of CALayer and integration in UIView via Categories.

"Translation" of AUISelectiveBordersLayer is easy, but integration point is a bit tricky. In obj-c it's done like:

@implementation UIView (AUISelectiveBorder)

+(Class) layerClass {
    return [AUISelectiveBordersLayer class];
}

Is there any way to translate this to MonoTouch? It looks like overriding a static method, but I don't see anything like layerClass or layerType in MT.

回答1:

Fortunately I found that it works via subclassing UIView:

public class UIViewWithSelectiveBorders : UIView {

    [Export("layerClass")]
    public static Class LayerClass () {
        return new Class (typeof(SelectiveBorderLayer));
    }
}

At the moment that's enough for my tasks, but a more general question is still actual: is there a way to change that without subclassing UIView (for example, if I want to override that for all UILabels)