简体   繁体   English

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

[英]How to Bind extension methods in Monotouch?

I'm having a hard time to define the correct bindings for an IOS static library. 我很难为IOS静态库定义正确的绑定。 The include file contains some extension methods defined as: 包含文件包含一些扩展方法,这些扩展方法定义为:

#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

The Monotouch documentation ( Binding Class Extensions ) is not very clear how to actually handle this. Monotouch文档( Binding Class Extensions )不是很清楚如何实际处理。

Should this also be defined as an extension C# method? 是否也应将其定义为扩展C#方法? Or do we have to define this in the class "LayerEffects"? 还是我们必须在“ LayerEffects”类中定义它?

Update Following mapping does not work: 更新以下映射不起作用:

[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);

}

I think you would have to define a new class to make a binding: 我认为您必须定义一个新类来进行绑定:

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

}

But this doesn't really help your situation. 但这并不能真正帮助您解决问题。

You want to use this on any UIView right? 您想在任何UIView上使用它吗?

It might be easier to translate the code underneath into C#. 将下面的代码转换为C#可能会更容易。 These methods don't look too hard to implement. 这些方法看起来并不难实现。 For example, I think setCornerRadius is just this: 例如,我认为setCornerRadius就是这样:

myView.Layer.CornerRadius = 3f;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM