Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

705
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda