MonoTouch - 如何覆盖静态 UIView.layerClass

Sha*_*dix 1 static-methods objective-c xamarin.ios

我正在尝试将AUISelectiveBordersView 移植到 MonoTouch。它基本上是通过类别的子类CALayer和集成UIView

AUISelectiveBordersLayer 的“翻译”很容易,但集成点有点棘手。在 obj-c 中,它是这样完成的:

@implementation UIView (AUISelectiveBorder)

+(Class) layerClass {
    return [AUISelectiveBordersLayer class];
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将其转换为 MonoTouch?它看起来像重写静态方法,但我没有看到像什么layerClasslayerType在MT。

Sha*_*dix 5

幸运的是,我发现它可以通过继承 UIView 来工作:

public class UIViewWithSelectiveBorders : UIView {

    [Export("layerClass")]
    public static Class LayerClass () {
        return new Class (typeof(SelectiveBorderLayer));
    }
}
Run Code Online (Sandbox Code Playgroud)

目前这对于我的任务来说已经足够了,但一个更普遍的问题仍然是实际的:有没有办法在没有子类化的情况下改变它UIView(例如,如果我想为所有的UILabels覆盖它)