如何在Monotouch中绑定扩展方法?

时间:2012-10-31 09:34:02

标签: c# ios xamarin.ios

我很难为IOS静态库定义正确的绑定。 include文件包含一些定义为:

的扩展方法
#import <Foundation/Foundation.h>
@interface UIView(LayerEffects)

// set round corner
- (void) setCornerRadius : (CGFloat) radius;
// set inner border
- (void) setBorder : (UIColor *) color width : (CGFloat) width;
// set the shadow
// Example: [view setShadow:[UIColor blackColor] opacity:0.5 offset:CGSizeMake(1.0, 1.0) blueRadius:3.0];
- (void) setShadow : (UIColor *)color opacity:(CGFloat)opacity offset:(CGSize) offset blurRadius:(CGFloat)blurRadius;

@end

Monotouch文档(Binding Class Extensions)不太清楚如何实际处理这个问题。

这是否也应该被定义为扩展C#方法?或者我们是否必须在“LayerEffects”类中定义它?

更新以下映射不起作用:

[BaseType (typeof (UIView))]
interface LayerEffects{

    [Bind ("setCornerRadius:")]
    void SetCornerRadius ([Target] UIView uiView, float width);

    [Bind ("setBorder:width")]
    void SetBorder ([Target] UIView uiView, UIColor color, float width);

    [Bind ("setShadow:opacity:offset:blurRadius")]
    void SetShadow ([Target] UIView uiView, UIColor color, float opacity, SizeF offset, float blurRadius);

}

1 个答案:

答案 0 :(得分:0)

我认为您必须定义一个新类来进行绑定:

[BaseType(typeof(UIView))]
public interface UIViewLayerEffects
{

}

但这对你的情况没有帮助。

你想在任何UIView权利上使用它吗?

将下面的代码翻译成C#可能更容易。这些方法看起来不太难实现。例如,我认为setCornerRadius就是这样:

myView.Layer.CornerRadius = 3f;