答案 0 :(得分:1)
就像@Quantic所说,你只需在文本中添加一个新行,如:
Label.Text = "I got it. Take me to the" + Environment.NewLine + "Home Screen";
与做的相同:
Label.Text = "I got it. Take me to the\nHome Screen";
或使用StackLayout
:
StackLayout layout = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
new Label { Text = "I got it. Take me to the" },
new Label { Text = "Home Screen" },
}
}
所有这一切,您可能不想这样做,因为不同的屏幕将具有不同的宽度,因此您需要考虑到这一点。不同的设备也可以更改应用中的文字大小,这样也会影响尺寸。
*编辑:如果您希望Label
的尾端截断文字,那么您可以设置LineBreakMode
的{{1}},如下所示:
Label
有时这不起作用取决于您的Label.LineBreakMode = LineBreakMode.TailTruncation
所包含的布局类型,因此如果它不起作用,请告诉我您将Label
存储在哪种布局中
因此,如果Label
中有Label
,则截断可能无法在Android上正常运行。请尝试将StackLayout
放入Label
。对于遇到此问题的其他人,请参阅this帖子。
答案 1 :(得分:1)
<Grid Padding="0, 10, -10, 10" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OpenHomePageCommand}"/>
</Grid.GestureRecognizers>
<controls:ExtendedLabel x:Name="SimpleLabel"
Grid.Row="0"
Grid.Column="0"
FontFamily="OpenSans-Semibold"
FontSize="16.4"
InputTransparent="True"
Text="I got it. Take me to the "
TextColor="{StaticResource Onahau}"
VerticalOptions="EndAndExpand" />
<controls:ExtendedLabel x:Name="UnderlineLabel"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
FontFamily="OpenSans-Semibold"
FontSize="16.4"
InputTransparent="True"
IsUnderline="True"
Text="Home Screen"
TextColor="{StaticResource Onahau}"
VerticalOptions="EndAndExpand" />
</Grid>
答案 2 :(得分:0)
你不能让2个标签彼此相邻,包装工作就像样品一样,需要非矩形边界框和Xamarin.Forms(或我知道的任何其他UIKit)不支持它
但是您可以使用具有多个Spans的单个Label
:
var formattedString = new FormattedString ();
formattedString.Spans.Add (new Span { BackgroundColor = Color.Red, ForegroundColor = Color.Olive, Text = "I got it. Take me to the " });
formattedString.Spans.Add (new Span { BackgroundColor = Color.Black, ForegroundColor = Color.White, Text = "Home Screen.", FontAttributes=FontAttributes.Bold });
var label = new Label {
FormattedText = formattedString
};