无论目标设备的分辨率如何,我都想让标签按比例显示相同的大小
我有以下代码
<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 的新手,但这似乎是一件很明显想要做的事情。
最佳答案
您可以使用 Xamarin 表单 NamedSize Enumeration
您可以选择:
- 默认
- 大
- 中等
- 微型
- 小
示例:
<Label FontSize="small" Text="Joe"></Label>
<Label FontSize="Large" Text="Joe"></Label>
关于c# - XAML 动态更改字体大小 iOS Xamarin 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38180955/