Use this Xamarin.Forms plugin to display HTML content into a label.
** MID YEAR UPDATE **
- Xamarin.Forms 3.0
- IsHtml and RemoveHtmlTags properties removed
- HtmlAgilityPack dependency removed
- Navigating and Navitated events added when users tap on links
- Namespace and assembly name changed
- 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();
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.
If you need to customize something in Android or iOS you can use inline CSS, for example:
<span style="color: green">...</span>
For underlined text use the <u> tag:
<u>Some underlined text</u>
For links: remember to add the schema (http:// https:// tel:// mailto:// ext...)
- Text
- FontAttributes
- FontFamily
- FontSize
- TextColor
- HorizontalTextAlignment
Navigating Navigated
xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=HtmlLabel.Forms.Plugin"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}"/>
xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=HtmlLabel.Forms.Plugin"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}" htmlLabel:HtmlLabel.MaxLines="2"/>
var label = new HtmlLabel();
label.Text = "..htmlstring.."
- Using Links and custom fonts together could not work properly on iOS.
- Images won't be displayed on Android (TextView limitation).
Contributions are welcome!
Under MIT, see LICENSE file.