2017-01-24 11 views

回答

3
  1. 如解釋here所示,將字體添加到您的平臺中。
  2. 創建一個平臺像反映了一個字體樣式:

    <OnPlatform x:Key="NormalFont" x:TypeArguments="x:String" 
           iOS="Montserrat" Android="Montserrat" 
           WinPhone="Assets/Fonts/Montserrat-Regular.ttf#Montserrat"/> 
    
  3. 與任何下列選項中使用它:

    • 直接使用: <Label Text="test" FontFamily="{StaticResource NormalFont}"/>

    • 使用帶匿名樣式(影響應用中的所有標籤):

      <Style TargetType="Label"> 
          <Setter Property="FontFamily" Value="{StaticResource NormalFont}"/> 
      </Style> 
      
    • 使用名爲風格:

      <Style x:Key="TitleStyle" TargetType="Label"> 
          <Setter Property="FontFamily" Value="{StaticResource Boldfont}"/> 
      </Style> 
      
      <Label Text="Options" Style="{StaticResource TitleStyle}"/> 
      
0

如果你不想做實現這個你自己,你可以使用CustomFontEffect我們增加在CommunityToolkit爲Xamarin形式:https://github.com/FormsCommunityToolkit/FormsCommunityToolkit/tree/dev/src

有一個示例項目增加了,但總體使用如下:

<Label Text="Comic Sans is tha bomb!"> 
    <Label.Effects> 
     <effects:CustomFontEffect FontPath="ComicSaaaaaans.ttf" FontFamilyName="Comic Sans MS" /> 
    </Label.Effects> 
</Label> 
+0

Broken Link,請修改。 – Diomedes

+1

完成後,添加工具箱的新鏈接 – Depechie

相關問題