Skip to main content

Xamarin.Form's autosized label

Please see Sabon Rai Software's solution here: https://sabonrai.wordpress.com/2016/02/14/xamarin-forms-xaml-label-adjusts-font-size-to-fit-width-of-content/#comment-3002

In short, the AutosizeLabelRenderer code looks like this:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
[assembly: ExportRenderer (typeof(AutosizeLabel), typeof(AutosizeLabelRenderer))]
namespace <NAMESPACE>
{
 public class AutosizeLabelRenderer : LabelRenderer
 {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            var label = Control as UILabel;
            if (label != null)
            {
                label.AdjustsFontSizeToFitWidth = true;
                label.Lines = 1;
                label.BaselineAdjustment = UIBaselineAdjustment.AlignCenters;
                //label.LineBreakMode = UILineBreakMode.Clip;
                label.MinimumScaleFactor = new System.nfloat(0.5);
            }
        }
    }
}

Comments

Popular posts from this blog

Xamarin.Forms OnPlatform - TabbedPage vs NavigationPage

I switched my start page from a NavigationPage to a TabbedPage and all of a sudden the content overwrote the the carrier/battery row. I looked into this and discovered that the TabbedPage does not offset itself below this header in iOS (but works for android and windows). The solution is to add a platform dependent offset or padding thickness of 20 pixels.

dbapps.com: top 200 iOS apps

Repurposed dbapps.com to present the iOS app data I've collected over the years. It shows the top 200 FREE, PAID, and GROSSING iOS apps on the apple app store along w/ their deltas over several time periods. I've used this report to help guide my investments in the mobile app space. Here's a screenshot: