c# - XAML 动态更改字体大小 iOS Xamarin 应用程序

标签 c# ios xaml xamarin xamarin.forms

无论目标设备的分辨率如何,我都想让标签按比例显示相同的大小

我有以下代码

<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/

相关文章:

c# - 带空格的 WPF/XAML ResourceDictionary

c# - Windows Phone 8.1 应用构建中缺少 WMAppManifest.xml

c# - for循环条件问题

ios - 在 iOS 中将 self.navigationItem.backBarButtonItem 对齐到设备的左侧

ios - 如何在 swift iOS swift cocoa 框架中使用 Objective C 静态框架

wpf - 根据最大按钮的内容均匀大小的按钮

c# - "Security"和 ASP.NET 路由引擎的问题

c# - 文件上传进度

ios - 为什么该方法要在最后运行?

xaml - 防止系统 FontSize 更改影响 Xamarin 应用程序中的大小