【问题标题】:MonoTouch - how to override static UIView.layerClassMonoTouch - 如何覆盖静态 UIView.layerClass
【发布时间】:2012-11-21 05:59:10
【问题描述】:

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

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

@implementation UIView (AUISelectiveBorder)

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

有什么办法可以把它翻译成 MonoTouch?它看起来像是覆盖了一个静态方法,但我在 MT 中看不到 layerClasslayerType 之类的东西。

【问题讨论】:

    标签: objective-c xamarin.ios static-methods


    【解决方案1】:

    幸运的是,我发现它可以通过子类化 UIView 来工作:

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

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

    【讨论】:

    • 有办法的。但它涉及的工作不仅仅是继承 UILabel。您在上面的操作方式很少。
    • 你能给个链接吗?我很感兴趣,以防将来的任务需要它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多