xamarin - 我无法让我的自定义字体与 Xamarin.Forms 一起使用
问题描述
我创建了这个资源:
<?xml version="1.0" encoding="utf-8"?> <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CustomFrameApp.App">
<Application.Resources>
<ResourceDictionary>
<OnPlatform x:TypeArguments="x:String" x:Key="NewFont">
<On Platform="iOS" Value="Camber_Medium_Regular" />
</OnPlatform>
</ResourceDictionary>
</Application.Resources> </Application>
添加到 info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIAppFonts</key>
<array>
<string>Camber_Medium_Regular.otf</string>
</array>
</dict>
</plist>
并在我的 XAML 中使用
<Label FontSize="12px" Text="ABCD" TextColor="Black" VerticalOptions="Center" HorizontalOptions="Center" FontFamily="{StaticResource NewFont}" />
但是字体仍然没有被使用
我按照建议将它们添加为捆绑资源,它们位于 iOS 的资源文件中
有谁知道可能出了什么问题?
解决方案
根据Xamarin.Forms中的字体,请确认三件事:
- 如果您在资源文件中添加了名为 Camber_Medium_Regular.ttf 的字体文件 tat,并且Build Action:BundleResource
2.更新Info.plist,像这样:
<key>UIAppFonts</key>
<array>
<string>Camber_Medium_Regular.ttf</string>
</array>
3.按名称引用
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Camber_Medium_Regular" />
<On Platform="Android" Value="Lobster-Regular.ttf#Lobster-Regular" />
<On Platform="UWP" Value="Assets/Fonts/Lobster-Regular.ttf#Lobster" />
</OnPlatform>
推荐阅读
- reactjs - 从 API 加载动态 NavItem 不起作用
- c - 在keil中编译代码时遇到链接错误
- android - 使用 ViewBinding 时如何突出显示 RecyclerView 中单击的项目?
- java - LOGGER.INFO 和 LOGGER.DEBUG 未填充到主机 (JAVA)
- git - 调试 git bundle(生成的文件太大)
- python-3.x - 我有事要问,我刚刚学会了如何使用 while 循环,但遇到了一个问题。为什么这2个结局不一样
- r - 使用 R 在每行中使用日期过滤出数据行
- python - 使用以下条件对字符串进行排序
- docker - 在docker compose中使用相同卷的多个docker镜像容器?
- makefile - 使用 makefile 阅读和跳过注释行的更好方法