很棒的字体无法在 iOS 上使用
Font awesome not working on iOS
我正在尝试让字体在我的应用程序中运行。
我为此制作了一个自定义标签:
public FALabel()
{
FontFamily = Device.OnPlatform(null, "FontAwesome", "/Assets/fontawesome-webfont.ttf#FontAwesome");
}
我已将字体添加到 2 个项目中。
在 android 上它按预期工作 - 在 IOS 上它没有,请参见下图。
这应该是 6 个不同的项目 - none 其中一个是问号。
我将字体添加到 info.plist
并将生成操作设置为始终复制。
我使用以下代码段验证字体已安装在 IOS 上:
private void LogFonts()
{
foreach (NSString family in UIFont.FamilyNames)
{
foreach (NSString font in UIFont.FontNamesForFamilyName(family))
{
Console.WriteLine(@"{0}", font);
}
}
}
我的字体 awesome unicodes 是从一个字符串中获取的:
...
public static string FAGlass = "\uf000";
public static string FAMusic = "\uf001";
public static string FASearch = "\uf002";
...
如前所述,它在 Android 上按预期工作 - 我错过了什么?
Info.plist的相关部分
<key>UIAppFonts</key>
<array>
<string>FontAwesome.ttf</string>
</array>
设置 FontFamily 时传递给 Device.OnPlatform 调用的第一个参数是要在 iOS 平台上使用的值。
在您的情况下,您已将其设置为 null。
我这样设置我的:
FontFamily = Device.OnPlatform("FontAwesome", "FontAwesome", @"/Assets/Fonts/fontawesome - webfont.ttf#FontAwesome");
//For Android, a custom renderer is required in any case, which can specify the correct font without utilizing the FontFamily property, but I prefer to specify it there as well, for clarity or if you decide to support multiple fonts
而且效果很好。
你的设备顺序有误:先是iOS,Android然后是Windows:
public static Void OnPlatform (Action iOS, Action Android, Action WinPhone, Action Default)
参考:https://developer.xamarin.com/api/member/Xamarin.Forms.Device.OnPlatform/
我正在尝试让字体在我的应用程序中运行。
我为此制作了一个自定义标签:
public FALabel()
{
FontFamily = Device.OnPlatform(null, "FontAwesome", "/Assets/fontawesome-webfont.ttf#FontAwesome");
}
我已将字体添加到 2 个项目中。
在 android 上它按预期工作 - 在 IOS 上它没有,请参见下图。
这应该是 6 个不同的项目 - none 其中一个是问号。
我将字体添加到 info.plist
并将生成操作设置为始终复制。
我使用以下代码段验证字体已安装在 IOS 上:
private void LogFonts()
{
foreach (NSString family in UIFont.FamilyNames)
{
foreach (NSString font in UIFont.FontNamesForFamilyName(family))
{
Console.WriteLine(@"{0}", font);
}
}
}
我的字体 awesome unicodes 是从一个字符串中获取的:
...
public static string FAGlass = "\uf000";
public static string FAMusic = "\uf001";
public static string FASearch = "\uf002";
...
如前所述,它在 Android 上按预期工作 - 我错过了什么?
Info.plist的相关部分
<key>UIAppFonts</key>
<array>
<string>FontAwesome.ttf</string>
</array>
设置 FontFamily 时传递给 Device.OnPlatform 调用的第一个参数是要在 iOS 平台上使用的值。 在您的情况下,您已将其设置为 null。
我这样设置我的:
FontFamily = Device.OnPlatform("FontAwesome", "FontAwesome", @"/Assets/Fonts/fontawesome - webfont.ttf#FontAwesome");
//For Android, a custom renderer is required in any case, which can specify the correct font without utilizing the FontFamily property, but I prefer to specify it there as well, for clarity or if you decide to support multiple fonts
而且效果很好。
你的设备顺序有误:先是iOS,Android然后是Windows:
public static Void OnPlatform (Action iOS, Action Android, Action WinPhone, Action Default)
参考:https://developer.xamarin.com/api/member/Xamarin.Forms.Device.OnPlatform/