簡體   English   中英

無法在UIButton中使用自定義字體

[英]Unable to use Custom Font in UIButton

我試圖在我的應用程序中使用自定義字體,這是ttf格式。 在項目設置中,我添加了如下所示的字體名稱。

在此輸入圖像描述

我在我的資源文件夾中添加了該字體,如下所示

在此輸入圖像描述

而我試圖使用的字體就是這個 在此輸入圖像描述

_enterButton.titleLabel.font =  [UIFont fontWithName:@"Venus Rising" size:45.0];

如果我使用Arial或其他字體,它工作正常。 但是當我嘗試使用這種字體時,它根本不起作用。 誰能告訴我為什么?

我下載了字體,因為我認為它的名稱不同於文件的名稱。 看看這張圖片。

在此輸入圖像描述

另外,請不要忘記將應用程序的Info.plist添加到“應用程序提供的字體”下的名稱。 希望能幫助到你! :)

你錯過了info.plist中字體的擴展,我的意思是在Info.plist中,“應用程序提供的字體”你需要設置“Venus Rising.ttf”然后你的問題就會解決

我前幾天遇到了同樣的問題。 對我來說,字體名稱與ttf文件名不同。

嘗試使用此循環檢查應用中可用的所有字體:

for (id familyName in [UIFont familyNames]) {
    NSLog(@"family name : %@",familyName);
    for (id font in [UIFont fontNamesForFamilyName:familyName]) {
        NSLog(@"    %@",font);
    }
}

在您的情況下,Venus Rising應該顯示為姓氏,但您在代碼中應使用的字體的確切名稱可能是VenusRisingRegular或類似名稱。

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: @"Grinched" size:24]];
[label1 setText:@"Grinched Font"];
[[self view] addSubview:label1];

UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: @"Energon" size:18]];
[label2 setText:@"Energon Font"];
[[self view] addSubview:label2];

請試試這個。

它可能對你有所幫助

暫無
暫無

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

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