Xamarin Forms Label - Justify?

前端 未结 10 2057

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条回答
  •  萌比男神i
    2020-12-07 02:12

    As it can't be done directly within a label, a workaround is to use the new FlexLayout from Xamarin.Forms 3. The idea is to split the text at space character and insert corresponding label in the FlexLayout with JustifyContent set to SpaceBetween.

    Example :

    XAML

    
        
    
    

    Code behind

    var textparts = "This is a long text to be justified"
                    .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                    .Select(x => new Label
                    {
                        Text = x,
                        FontSize = 12,
                        TextColor = Color.FromHex("#555555"),
                        Margin = new Thickness(1, 0)
                    });
    
                foreach (var textpart in textparts)
                    TextContainer.Children.Add(textpart);
    

提交回复
热议问题