I want to port this to C#.
I don't know how I should convert this:
@property (nonatomic, strong, readonly) CAGradientLayer *layer;
The layer
is the default layer for the UIView. Xamarin already has a Layer
property. How do I overwrite this? Do I need to overwrite it?
I also tried it with
public CAGradientLayer layer { [Export ("Layer")] get; [Export ("Layer:")] set; }
but the app crashes (System.Reflection.TargetInvocationException - NullReferenceException when dequeuing the cell) if I want to set the colors of the layer. Furthermore it should be readonly.
Then I saw in the documentation how it could be converted:
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);
}
}
This doesn't help me because I need something like SetFillColors so that I can use CGColor[]
array. But there is no such function.
How do I create my UIView
with my custom CAGradientLayer
in C# with Monotouch?