ios - 自定义渲染器在 iOS + 库中不起作用

标签 ios forms xamarin custom-renderer

我不知道为什么我的 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 上运行良好。

https://github.com/matteobortolazzo/HtmlLabelPlugin

最佳答案

向您的 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/

相关文章:

javascript - 表单提交与另一个表单的数据

xaml - 如果内容按行方向放置,如何减少 Flex 布局中内容之间的空间?

Xamarin Forms 导航页面图标大小

ios - 新应用程序安装时会调用新 Realm 迁移

ios - Firebase 数据库权限被拒绝使用 swift 4.2 时遇到的错误

ios - 如何停止执行 PDFNet 操作?

ios - 隐藏一个 View 并在触摸按钮时取消隐藏另一个 View

javascript - jQuery表单提交后的冗余参数

xamarin - 如何使用 View 模型调用异步命令?

javascript - 使用JS向文本字段添加字符