Skip to content

closetoyou293/HtmlLabelPlugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 2.0;
  • 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: <a>, <b>, <br>, <em>, <i>, <p>, <strong>, <u>, <ul> <li>, <div>.

FontAttributes, FontFamily, FontSize, TextColor, HorizontalTextAlignment are converted into inline CSS in a wrapping <div> 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:

<table style="border: 1px solid gray">...</table>

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);

Contributions

Contributions are welcome!

License

Under MIT, see LICENSE file.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%