【发布时间】:2016-07-04 09:15:39
【问题描述】:
无论目标设备的分辨率如何,我想让标签按比例显示相同的大小
我有以下代码
<StackLayout
Orientation="Vertical" Margin="0,0,0,0" Padding="0,0,0,0"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label Text="{Binding AccountName}"
Style="{StaticResource labelStylePrimaryBold}"
HorizontalOptions="StartAndExpand" />
</StackLayout>
我的 App.xaml 中有上面的代码和这个
<Style x:Key="labelStylePrimaryBold" TargetType="Label">
<Setter Property="TextColor" Value="#414042" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="FontSize" Value="15" />
</Style>
我需要在我的应用程序中提供此功能,我在 https://developer.xamarin.com/guides/xamarin-forms/user-interface/text/fonts/
label.FontSize = Device.OnPlatform (
24,
Device.GetNamedSize (NamedSize.Medium, label),
Device.GetNamedSize (NamedSize.Large, label)
);
但是我的标签没有ID,我该如何链接呢?
我对 Xamarin 很陌生,但这似乎是一件很明显的事情。
【问题讨论】:
-
该链接包含在 Xaml 中执行此操作的代码。但如果您仍想在后端代码中执行此操作,请使用
X:Name将 id 添加到您的标签。 -
我看不到在 XAML 中设置字体大小的代码?我在 App.xaml 中也需要它?
-
<Label.FontSize> <OnPlatform x:TypeArguments="x:Double" iOS="10" Android="11" WinPhone="12" /> </Label.FontSize>你可以在 xaml 中使用它。 -
提到不同的平台,我需要iphone 4、iphone 5、ipad 2等。
-
要做到这一点,您可能需要检查屏幕的宽度和高度来确定手机。我在这里回答了类似的问题:stackoverflow.com/questions/38096347/… ...
标签: c# ios xaml xamarin xamarin.forms