0

I've made a Custom Renderer for a Label to display html formatted text.

The problem is that unlike in Android, in IOS the text is to small and i can't find a way to change it.

My code

IOS

[assembly:ExportRenderer(typeof(HtmlFormattedLabel), typeof(HtmlFormattedLabelRenderer))]
namespace YmoApp.iOS
{
    public class HtmlFormattedLabelRenderer : LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            var view = (HtmlFormattedLabel)Element;

            if (view == null) return;

            var attr = new NSAttributedStringDocumentAttributes();
            var nsError = new NSError();
            attr.DocumentType = NSDocumentType.HTML;

            var myHtmlData = NSData.FromString(view.Text, NSStringEncoding.UTF8);

            Control.AttributedText = new NSAttributedString(myHtmlData, attr, ref nsError);

        }
    }
}

Android

[assembly:ExportRenderer(typeof(HtmlFormattedLabel), typeof(HtmlFormattedLabelRenderer))]
namespace YmoApp.Droid
{
    public class HtmlFormattedLabelRenderer : LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            var view = (HtmlFormattedLabel)Element;
            if (view == null) return;

            Control.SetText(Html.FromHtml(view.Text.ToString()), TextView.BufferType.Spannable);
        }
    }
}

PCL

var descriptionLabel = new HtmlFormattedLabel()
{
    Text = "<http><body style='font-size; 20px'><p style='text-align: justify; font-family: Arial, Helvetica, sans-serif; font-size: 14px'>"
                + _imovel.Anuncio.Descricao + "</p></body></http>",
    Margin = new Thickness(20, 0)
};

descriptionLabel.FontSize = 14;

Nothing seems to take effect.

Tiago_nes
  • 843
  • 7
  • 30

2 Answers2

1

I would guess that your problem lies in setting your formatted font size to pixel height. iOS takes pixel values quite seriously and a font size of 14 px will end up very tiny when being rendered on a retina display.

Try using resolution independent font sizes and you should be good to go.

Also this looks very wrong to me:

<body style='font-size; 20px'>
Markus Michel
  • 2,289
  • 10
  • 18
0

The error is in <body style='font-size; 20px'>.

The ; sould be replaced with :.

Tiago_nes
  • 843
  • 7
  • 30