MonoTouch - 如何覆盖静态 UIView.layerClass [英] MonoTouch - how to override static UIView.layerClass

查看:21
本文介绍了MonoTouch - 如何覆盖静态 UIView.layerClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

"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];
}

有什么方法可以将其转换为 MonoTouch?它看起来像是覆盖了一个静态方法,但我在 MT 中看不到 layerClasslayerType 之类的东西.

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.

推荐答案

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

Fortunately I found that it works via subclassing UIView:

public class UIViewWithSelectiveBorders : UIView {

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

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

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)

这篇关于MonoTouch - 如何覆盖静态 UIView.layerClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆