Xam.Plugin.HtmlLabel 2.2.0

HTML Label

Use this Xamarin.Forms plugin to display HTML content into a label.

There is a newer version of this package available.
See the version list below for details.
Install-Package Xam.Plugin.HtmlLabel -Version 2.2.0
dotnet add package Xam.Plugin.HtmlLabel --version 2.2.0
<PackageReference Include="Xam.Plugin.HtmlLabel" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xam.Plugin.HtmlLabel --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Html Label Plugin for Xamarin.Forms

Use this Xamarin.Forms plugin to display HTML content into a label.

** NEW YEAR UPDATE **

  • Xamarin.Forms 2.5.0;
  • .NET Standard;
  • UWP partial support;
  • Added support for: FontAttributes, FontFamily, FontSize, TextColor and HorizontalTextAlignment;
  • HyperLinks support.

Setup

  • Available on NuGet: https://www.nuget.org/packages/Xam.Plugin.HtmlLabel
  • Install it in every Xamarin.Forms project.
  • iOS: AppDelegate.cs
    HtmlLabelRenderer.Initialize();
    global::Xamarin.Forms.Forms.Init();
    
  • Android: MainActivity.cs
    HtmlLabelRenderer.Initialize();
    global::Xamarin.Forms.Forms.Init(this, bundle);
    
  • UWP: App.xaml.cs
    var rendererAssemblies = new[] { typeof(HtmlLabelRenderer).GetTypeInfo().Assembly };
    Xamarin.Forms.Forms.Init(e, rendererAssemblies);
    HtmlLabelRenderer.Initialize();
    

How it works

On iOS and Android it uses the native HTML rendering capabilities of iOS's UILabel and Android's TextView.

UWP's TextBlock cannot renders HTML so the library parses the HTML and uses Inlines to display: &lt;a&gt;, &lt;b&gt;, &lt;br&gt;, &lt;em&gt;, &lt;i&gt;, &lt;p&gt;, &lt;strong&gt;, &lt;u&gt;, &lt;ul&gt; &lt;li&gt;, &lt;div&gt;.

FontAttributes, FontFamily, FontSize, TextColor, HorizontalTextAlignment are converted into inline CSS in a wrapping &lt;div&gt; for iOS and Android. UWP supports them natively.

Custom styling

If you need to customize something in Android or iOS you can use inline CSS, for example:

&lt;span style=&quot;color: green&quot;&gt;...&lt;/span&gt;

For underlined text use the <u> tag:
&lt;u&gt;Some underlined text&lt;/u&gt;

For links: remember to add the schema (http:// https:// tel:// mailto:// ext...)

Supported Properties

  • Text
  • FontAttributes
  • FontFamily
  • FontSize
  • TextColor
  • HorizontalTextAlignment

Custom Properties

  • MaxLines (int)
  • IsHtml (bool)
  • RemoveHtmlTags (bool)

Usage XAML

xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}" htmlLabel:HtmlLabel.MaxLines="2"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding PlainTextString}" htmlLabel:HtmlLabel.IsHtml="False"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}" htmlLabel:HtmlLabel.RemoveHtmlTags="True"/>

Usage C#

var label = new HtmlLabel();
label.Text = "..htmlstring.."
HtmlLabel.SetMaxLines(label, 3);

Limitations

  • SetMaxLines and LineBreakMode.TailTruncation do not work properly;
  • Links and custom fonts could not work properly on iOS.

Contributions

Contributions are welcome!

License

Under MIT, see LICENSE file.

Html Label Plugin for Xamarin.Forms

Use this Xamarin.Forms plugin to display HTML content into a label.

** NEW YEAR UPDATE **

  • Xamarin.Forms 2.5.0;
  • .NET Standard;
  • UWP partial support;
  • Added support for: FontAttributes, FontFamily, FontSize, TextColor and HorizontalTextAlignment;
  • HyperLinks support.

Setup

  • Available on NuGet: https://www.nuget.org/packages/Xam.Plugin.HtmlLabel
  • Install it in every Xamarin.Forms project.
  • iOS: AppDelegate.cs
    HtmlLabelRenderer.Initialize();
    global::Xamarin.Forms.Forms.Init();
    
  • Android: MainActivity.cs
    HtmlLabelRenderer.Initialize();
    global::Xamarin.Forms.Forms.Init(this, bundle);
    
  • UWP: App.xaml.cs
    var rendererAssemblies = new[] { typeof(HtmlLabelRenderer).GetTypeInfo().Assembly };
    Xamarin.Forms.Forms.Init(e, rendererAssemblies);
    HtmlLabelRenderer.Initialize();
    

How it works

On iOS and Android it uses the native HTML rendering capabilities of iOS's UILabel and Android's TextView.

UWP's TextBlock cannot renders HTML so the library parses the HTML and uses Inlines to display: &lt;a&gt;, &lt;b&gt;, &lt;br&gt;, &lt;em&gt;, &lt;i&gt;, &lt;p&gt;, &lt;strong&gt;, &lt;u&gt;, &lt;ul&gt; &lt;li&gt;, &lt;div&gt;.

FontAttributes, FontFamily, FontSize, TextColor, HorizontalTextAlignment are converted into inline CSS in a wrapping &lt;div&gt; for iOS and Android. UWP supports them natively.

Custom styling

If you need to customize something in Android or iOS you can use inline CSS, for example:

&lt;span style=&quot;color: green&quot;&gt;...&lt;/span&gt;

For underlined text use the <u> tag:
&lt;u&gt;Some underlined text&lt;/u&gt;

For links: remember to add the schema (http:// https:// tel:// mailto:// ext...)

Supported Properties

  • Text
  • FontAttributes
  • FontFamily
  • FontSize
  • TextColor
  • HorizontalTextAlignment

Custom Properties

  • MaxLines (int)
  • IsHtml (bool)
  • RemoveHtmlTags (bool)

Usage XAML

xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}" htmlLabel:HtmlLabel.MaxLines="2"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding PlainTextString}" htmlLabel:HtmlLabel.IsHtml="False"/>
xmlns:htmlLabel="clr-namespace:Plugin.HtmlLabel;assembly=Plugin.HtmlLabel"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}" htmlLabel:HtmlLabel.RemoveHtmlTags="True"/>

Usage C#

var label = new HtmlLabel();
label.Text = "..htmlstring.."
HtmlLabel.SetMaxLines(label, 3);

Limitations

  • SetMaxLines and LineBreakMode.TailTruncation do not work properly;
  • Links and custom fonts could not work properly on iOS.

Contributions

Contributions are welcome!

License

Under MIT, see LICENSE file.

Release Notes

Xamarin.Forms 2.5.0
           .NET Standard 1.3
           UWP partial support
           added support for: FontAttributes, FontFamily, FontSize, TextColor and HorizontalTextAlignment
           HyperLinks support
           2.2.0 => List tags Android support

Showing the top 1 GitHub repositories that depend on Xam.Plugin.HtmlLabel:

Repository Stars
gruan01/XFControls
Xamarin.Forms Custom Control

Version History

Version Downloads Last updated
3.0.2.2 14,597 3/18/2019
3.0.2.2-beta 67 3/18/2019
3.0.2.1 21,618 11/25/2018
3.0.1.6 15,057 8/26/2018
3.0.1.3-beta 1,424 6/13/2018
2.2.0 19,246 3/24/2018
2.1.5 451 3/7/2018
2.1.4 1,733 2/5/2018
2.1.3 275 2/3/2018
2.1.2 331 1/29/2018
2.1.1 312 1/28/2018
2.1.0 606 1/15/2018
1.0.4 5,186 7/11/2017
Show less