You can try this one:
1. create custom control in your PCL project:
using Xamarin.Forms;
namespace XYZ.CustomControl
{
//convert label text from HTML to simple display form
public class CustomLabel: Label
{
}
}
2. Android renderer:
using Android.Text;
using Android.Widget;
using XYZ.CustomControl;
using XYZ.Droid.Renderer;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CustomLabel), typeof(HtmlFormattedLabelRenderer))]
namespace XYZ.Droid.Renderer
{
public class HtmlFormattedLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var view = (CustomLabel)Element;
if (view == null) return;
if (!string.IsNullOrEmpty(Control.Text))
{
if (Control.Text.Contains("<a"))
{
var a = Control.Text.IndexOf("<a");
var b = Control.Text.IndexOf("</a>");
var d = Control.Text.Length;
var c = Control.Text.Length - Control.Text.IndexOf("</a>");
int length = b - a+4;
string code = Control.Text.Substring(a , length);
Control.SetText(Html.FromHtml(view.Text.ToString().Replace(code,string.Empty)), TextView.BufferType.Spannable);
}
else
Control.SetText(Html.FromHtml(view.Text.ToString()), TextView.BufferType.Spannable);
}
}
}
}
iOS renderer
using Foundation;
using XYZ.CustomControl;
using XYZ.iOS.Renderer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CustomLabel),
typeof(HtmlFormattedLabelRendereriOS))]
namespace XYZ.iOS.Renderer
{
public class HtmlFormattedLabelRendereriOS:LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var view = (CustomLabel)Element;
if (view == null) return;
var attr = new NSAttributedStringDocumentAttributes();
var nsError = new NSError();
attr.DocumentType = NSDocumentType.HTML;
Control.AttributedText = new NSAttributedString(view.Text, attr, ref nsError);
var mutable = Control.AttributedText as NSMutableAttributedString;
UIStringAttributes uiString = new UIStringAttributes();
uiString.Font = UIFont.FromName("Roboto-Regular",15f);
uiString.ForegroundColor = UIColor.FromRGB(130, 130, 130);
if (!string.IsNullOrEmpty(Control.Text))
{
if (Control.Text.Contains("<a"))
{
var text1 = Control.Text.IndexOf("<a");
var text2 = Control.Text.IndexOf("</a>");
int length = text2 - text1 + 4;
string code = Control.Text.Substring(text1, length);
Control.Text = Control.Text.Replace(code, string.Empty);
}
}
mutable.SetAttributes(uiString, new NSRange(0, Control.Text.Length));
}
}
}
Hope this helps you to solve your problem.