字体真棒不适用于iOS
我试图让字体真棒在我的应用程序工作。字体真棒不适用于iOS
我做了一个自定义标签可以这样做:
public FALabel()
{
FontFamily = Device.OnPlatform(null, "FontAwesome", "/Assets/fontawesome-webfont.ttf#FontAwesome");
}
我加入的字体到2个项目。
在Android上,它按预期工作 - 在IOS上它没有,请参阅下面的图片。
这应该是6级不同的项目 - 他们都不是一个问题的迹象。
我将字体添加到info.plist
,并将生成操作设置为始终复制。 我验证了字体安装在IOS与下面的代码片段:
private void LogFonts()
{
foreach (NSString family in UIFont.FamilyNames)
{
foreach (NSString font in UIFont.FontNamesForFamilyName(family))
{
Console.WriteLine(@"{0}", font);
}
}
}
我的字体真棒统一码是由一个字符串牵强:
...
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
和它工作得很好。
这是令人尴尬的...感谢:D –
你有错误的设备订单:是的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/
这是令人尴尬的......感谢:D –
@KasperSølvstrøm我们都做完了它;-) – SushiHangover
你可以包括你的info.plist的内容?你已经提到你在那里添加了字体并且可以枚举它,但是可能还有一些错误的声明。此外,我的fontawesome-webfont.ttf被设置为不复制,构建操作:捆绑资源,它位于Resources文件夹的根目录中。它效果很好。 – irreal
完成。我只设置构建动作,因为它没有工作..但仍然,字体安装 - 它很奇怪。 –
唯一不同的是我的设置,我可以看到的是我有 fontawesome-webfont.ttf 和我的实际字体文件确实叫做fontawesome-webfont.ttf –
irreal