簡體   English   中英

iOS自定義字體顯示在模擬器上,但不會在設備上顯示

[英]iOS custom font shows on simulator, but does not show on device

我在iOS應用程序中使用自定義字體

//Label which will display the current message
currentMessageLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 75, 300, 30)];
[currentMessageLabel setBackgroundColor:[UIColor clearColor]];
currentMessageLabel.font = [UIFont fontWithName:@"Baroque Script" size:24];
currentMessageLabel.textColor = [UIColor redColor];
currentMessageLabel.textAlignment = UITextAlignmentCenter;
[self.view addSubivew:currentMessageLabel];

我已將字體名稱添加到Info.plist文件中,手動將文件復制到捆綁資源。 它可以在模擬器上運行,但是當我在iPhone 5上運行應用程序時,它根本不顯示。 我該如何解決 ?

嘗試更改名稱

@"Baroque Script"

@"BaroqueScript"

(沒有空間)。

我有類似的問題,並通過這樣做解決了。 可能或可能不適合你。 試試看。

這可能是因為您的字體未復制到項目中(但已引用)。 因此,當您通過設備運行時,它無法找到您計算機上某處的字體。

執行以下步驟1)從項目中刪除字體。 2)拖放到您的項目並檢查復制項目並添加到目標。

如果您無法理解上述過程。 查看http://www.codigator.com/tutorials/using-custom-fonts-in-ios-application/並查看添加字體到項目部分。

伙計,這將打印所有字體名稱,你只需要復制確切的字體名稱

NSArray * familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];

NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:
                 [UIFont fontNamesForFamilyName:
                  [familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM