我不知道为什么我的 Xamarin.Forms 自定义渲染器在我将它放入库中并且仅在 iOS 上时不起作用,有人可以帮助我吗?
[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();
}
如果进入项目,它在 Android、UWP 和 iOS 上运行良好。
最佳答案
向您的 HtmlLabelRenderer
类添加一个什么都不做的 Initialize
静态方法,以确保您的渲染器类型在 Forms 之前加载
示例:
public static void Initialize()
{
}
用法:
在您的 AppDelegate
Forms.Init()
中,调用您的 Initialize 方法:
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);
}
关于ios - 自定义渲染器在 iOS + 库中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245662/