我想将它移植到C#。
我不知道我应该如何转换它:
@property (nonatomic, strong, readonly) CAGradientLayer *layer;
这layer
是 UIView 的默认层。Xamarin 已经拥有一个Layer
属性。我该如何覆盖这个?我需要覆盖它吗?
我也试过了
public CAGradientLayer layer { [Export ("Layer")] get; [Export ("Layer:")] set; }
但是如果我想设置图层的颜色,应用程序会崩溃(System.Reflection.TargetInvocationException - 使单元格出队时出现 NullReferenceException)。此外,它应该是只读的。
然后我在文档中看到了如何转换它:
public class BlueView : UIView
{
[Export ("layerClass")]
public static Class GetLayerClass ()
{
return new Class (typeof (BlueLayer));
}
public override void Draw (RectangleF rect)
{
// Do nothing, the Layer will do all the drawing
}
}
public class BlueLayer : CALayer
{
public override void DrawInContext (CGContext ctx)
{
ctx.SetFillColor (0, 0, 1, 1);
ctx.FillRect (Bounds);
}
}
这对我没有帮助,因为我需要像SetFillColors这样的东西才能使用CGColor[]
数组。但是没有这样的功能。
如何使用 Monotouch 在 C# 中创建我UIView
的自定义?CAGradientLayer