Xamarin Forms Label - Justify?

前端 未结 10 2041

I just wanted to ask if there is any way to justify text in a Label. I am using Xamarin Forms Xaml.

Thanks.

UPDATE:

相关标签:
10条回答
  • 2020-12-07 02:33

    The current way to do this is by using HorizontalTextAlignment and the values for the TextAlignment enumeration are:

    • Center = Center-aligned text
    • Start = Left-aligned
    • End = Right-aligned

    Center a label and its text example:

    <Label x:Name="Description" HorizontalTextAlignment="Center" VerticalOptions="Center" HorizontalOptions="Center" />

    0 讨论(0)
  • 2020-12-07 02:33

    Use the XAlign property

    Label lbl = new Label();
    lbl.Text = "I'm a Label!";
    lbl.XAlign = TextAligntment.Start; // Start, Center, End are valid
    
    0 讨论(0)
  • 2020-12-07 02:33

    In xaml you can use html to justify your text.

    <Label LineBreakMode="WordWrap" TextType="Html" TextColor="Black">
    <Label.Text>&lt;p style=&quot;text-align:justify;&quot;&gt; 
    Your text here
    &lt;p&gt;</Label.Text>
    
    0 讨论(0)
  • 2020-12-07 02:35

    Try this:

    <StackLayout HorizontalOptions="FillAndExpand" Padding="0, 10, 0, 10" Spacing="0">
          <Label Text="Test message" XAlign="Center"/>
          <Label FontSize="Small" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." LineBreakMode="WordWrap"
    XAlign="Center" />
    </StackLayout>
    
    0 讨论(0)
提交回复
热议问题