Custom renderer not working in iOS + library

Not sure why my own Xamarin.Forms renderer is not working, if I put it in a library and only on iOS, can anyone help me?

[assembly: ExportRenderer(typeof(HtmlLabel), typeof(HtmlLabelRenderer))]
namespace Plugin.HtmlLabel.iOS
{
    public class HtmlLabelRenderer : LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            if (Control == null) return;
            UpdateMaxLines();
            UpdateText();
        }

      

It works great on Android, UWP and iOS if in a project.

https://github.com/matteobortolazzo/HtmlLabelPlugin

+3


source to share


1 answer


Add a static do-nothing method Initialize

to your class HtmlLabelRenderer

to ensure that your renderer's types are loaded before forms

Example:

public static void Initialize()
{
}

      



Using:

In AppDelegate

before, Forms.Init()

call the Initialize method:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    Plugin.HtmlLabel.iOS.HtmlLabelRenderer.Initialize();
    global::Xamarin.Forms.Forms.Init();

    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}

      

+1


source







All Articles