Auto-scaling label fontsize in Xamarin

我是研究僧i 提交于 2019-12-11 15:49:13

问题


        <Label x:Name="mainLabel" 
           Grid.Row="0" 
           Grid.Column="0" 
           FontSize="50" 
           Grid.ColumnSpan="3"
           Grid.RowSpan="2"
           VerticalOptions="CenterAndExpand" 
           HorizontalOptions="CenterAndExpand" />

I am making a phone dialing interface and i have a label that outputs the numbers that are pressed.

Question: How can I make the font size of the label decreases and increases depending on the numbers typed so that it will fit on the label?

I tried googling all day but all the samples are outdated.

I am using the latest version of Xamarin and android API 27.


回答1:


You can have a FontSize with a binding property set for the Label.

eg:

<Label x:Name="mainLabel" 
           Grid.Row="0" 
           Grid.Column="0" 
           FontSize= "{Binding LabelFont}"
           Grid.ColumnSpan="3"
           Grid.RowSpan="2"
           VerticalOptions="CenterAndExpand" 
           HorizontalOptions="CenterAndExpand" />

You can have a TextChanged event triggered for the label where you check the length of label text goes above a value change to desired size and also for a length less than a value.

TextChanged event for Label can be implemented as mentioned in this link



来源:https://stackoverflow.com/questions/53117979/auto-scaling-label-fontsize-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!