2016-11-09 88 views
1

我試圖讓字體真棒在我的應用程序工作。字體真棒不適用於iOS

我做了一個自定義標籤可以這樣做:

public FALabel() 
{ 
    FontFamily = Device.OnPlatform(null, "FontAwesome", "/Assets/fontawesome-webfont.ttf#FontAwesome");  
} 

我加入的字體到2個項目。

在Android上,它按預期工作 - 在IOS上它沒有,請參閱下面的圖片。

enter image description here

這應該是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> 
+0

你可以包括你的info.plist的內容?你已經提到你在那裏添加了字體並且可以枚舉它,但是可能還有一些錯誤的聲明。此外,我的fontawesome-webfont.ttf被設置爲不復制,構建操作:捆綁資源,它位於Resources文件夾的根目錄中。它效果很好。 – irreal

+0

完成。我只設置構建動作,因爲它沒有工作..但仍然,字體安裝 - 它很奇怪。 –

+0

唯一不同的是我的設置,我可以看到的是我有 fontawesome-webfont.ttf和我的實際字體文件確實叫做fontawesome-webfont.ttf – irreal

回答

0

你設置的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 

和它工作得很好。

+0

這是令人尷尬的...感謝:D –