gpt4 book ai didi

Xamarin 在 XAML 中更改字体

转载 作者:行者123 更新时间:2023-12-02 01:03:26 24 4
gpt4 key购买 nike

如何更改 Xamarin.Forms XAML 中标签的字体?

预测不适用于 XAML 中的字体系列属性。

我在字体系列中尝试了 2 或 3 种字体,例如“Arial”,但它不起作用。

帮我解决这个问题。

<StackLayout Orientation="Vertical">
<Label Text="Welcome !"
VerticalOptions="Start"
HorizontalOptions="StartAndExpand"
FontFamily="Arial"
/>


</StackLayout>

最佳答案

store ttf file Location

  1. 安卓:YouNameSpace.Droid/Assets/Poppins-Light.ttf
  2. Ios: YouNameSpace.iOS/Resources/fonts/Poppins-Light.ttf
  3. iOS 需要在 info.plist 文件中加入 Below 行

    enter image description here

create static resource in App.xaml

<Application.Resources>
<ResourceDictionary>
<!-- FontFamily -->
<OnPlatform x:Key="PoppinsBold"
x:TypeArguments="x:String"
iOS="Poppins-Bold"
Android="Poppins-Bold.ttf#Poppins"/>

<OnPlatform x:Key="PoppinsLight"
x:TypeArguments="x:String"
iOS="Poppins-Light"
Android="Poppins-Light.ttf#Poppins" />

<!-- style for Lable -->
<Style x:Key="PoppinsBoldLabelStyle"
TargetType="{x:Type Label}">
<Setter Property="FontFamily"
Value="{StaticResource PoppinsBold}" />
</Style>

<Style x:Key="PoppinsLightLabelStyle"
TargetType="{x:Type Label}">
<Setter Property="FontFamily"
Value="{StaticResource PoppinsLight}" />
</Style>
</ResourceDictionary>
</Application.Resources>

use static resource in Lable

<Label Text="Hello"  Style="{StaticResource PoppinsBoldLabelStyle}"/>

关于Xamarin 在 XAML 中更改字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49150349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com