Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Custom Renderer to Override View Draw on iOS

$
0
0

Hello everyone!

Recently I created a custom renderer for android to draw a graphic Inheriting from View..
On android I simply overwritten the Draw method, and drew everything I need (arcs, circles and text) using canvas.

Now i went to iOS and ran into a problem.
In all the settings I've used and found over the internet, none of them have reached the override Draw method.

Follow the latest code i tried for iOS CustomRenderer:

using CoreGraphics;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(MyProjectName.CustomPieChart), typeof(MyProjectName.iOS.Renderers.CustomPieChartRenderer))]
namespace MyProjectName.iOS.Renderers
{
    class CustomPieChartRenderer : ViewRenderer<CustomPieChart, UIView>
    {
        private int ScaleFactor = 1;

        protected override void OnElementChanged(ElementChangedEventArgs<CustomPieChart> e)
        {
            base.OnElementChanged(e);
            if (Control == null)
            {
                var circleDotView = new UIView();
                SetNativeControl(circleDotView);
            }
        }

        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == CustomPieChart.DataValuesProperty.PropertyName)
            {
                this.SetNeedsDisplay();
            }
        }

        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
        }
    }
}

My custom control is:
public class CustomPieChart : View

My breakpoint never reachs the Draw method.
All my other custom renderes (without draw) are working perfect, those for Android too, including with draw.

Could someone tell me what I'm doing wrong?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>