I am going crazy trying to find the answer to this and having old posts about using NativeRenderer isn't helping!
I want a simple custom view to display lines that I draw in native code.
I have added to my xaml
xmlns:local="clr-namespace:ExecutiveScanner;assembly=ESXamlFormsPCL"
and
<local:SpectrumView />
I have added to my xaml.cs
public class SpectrumView : View { }
and in my iOS I have
[assembly: ExportRenderer(typeof(SpectrumView), typeof(SpectrumRenderer))]
and
public class SpectrumRenderer : ViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if ((e.OldElement != null) || (this.Element == null))
return;
if (Control != null)
{
Control.BackgroundColor = UIColor.Red;
}
SetNativeControl(new UIView());
}
public override void Draw(CGRect rect)
{
base.Draw(rect);
var context = UIGraphics.GetCurrentContext();
context.SetLineWidth(4);
UIColor.Red.SetFill();
UIColor.Blue.SetStroke();
var path = new CGPath();
path.AddLines(new CGPoint[]{
new PointF(100,200),
new PointF(160,100),
new PointF(220,200)
});
path.CloseSubpath();
context.AddPath(path);
context.DrawPath(CGPathDrawingMode.FillStroke);
}
}
Without SetNativeControl I get an Exception when it tries to display the page but what di I use for this ?
With new UIView() it doesn't call Draw! Should I use a different Native Control ? Should I create my own (How ?) or should I be using something other than Draw ?
``
Thanks for any help you can offer.
Wayne