Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

703
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda