Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

699
Views
Auto font size label Xamarin.Forms

I'm looking a way to create a render for a label. I need to show some information (for example: the barcode number) I need it to fit on the label reserved space

I want to show the info with the maxim font size has posible to fit on a single line. And I need to auto resize the text if it is necesary

I read a few blogs about the auto resize of the text on Xamarin, but all of the solutions looks complicated and outdated.

I would like to ask if some one has some code or some updated idea to solve this funccionality, thank you

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could try to use textview.SetAutoSizeTextTypeWithDefaults(AutoSizeTextType.Uniform) and uilabel.AdjustsFontSizeToFitWidth = true on Android and ios.

For Android

in your custom renderer:

class AutoFitLabel:LabelRenderer
{
    public AutoFitLabel(Context context) : base(context)
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged(e);
        Control.SetAutoSizeTextTypeWithDefaults(AutoSizeTextType.Uniform);
    }
}

For ios:

public class AutoFitLabel: LabelRenderer
{

    protected override void OnElementChanged (
        ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged (e);

        var label = Control as UILabel;
        if (label != null)
        {
            label.AdjustsFontSizeToFitWidth = true;             
        }
    }
}   

and call in your forms xaml:

<Label HeightRequest="80" HorizontalOptions="FillAndExpand" MaxLines="1"
               Text="This Label hasset Height to 80">
</Label>  
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!