2012-02-16 111 views
0

在我的應用程序中,我使用自定義字體。我複製我的font.ttf文件在我的項目目錄中,並使用以下代碼將自定義字體設置爲標籤。iPad中的自定義字體不起作用

[input setFont:[UIFont fontWithName: @"My Font" size: input.font.pointSize]] 

問題是它在iPhone 4.2模擬器中工作完美,但它在iPad 4.2模擬器中只顯示默認字體。如何解決這個問題?

+0

你是否在finder中打開字體文件並使用字體的全名而不是文件名(例如「My Custom Font」而不是「my_custom_font.ttf」) – henghonglee 2012-02-16 08:09:31

+0

我在信息中使用「我的字體名稱」 .plist文件 – 2012-02-16 08:20:45

+0

in info.plist你應該使用「my_custom_font.ttf」在UIAppFonts鍵下,但在代碼中你應該使用[UIFont fontWithName:「我的自定義字體」] 多數民衆贊成在混淆部分我 – henghonglee 2012-02-16 08:43:41

回答

0

以下代碼用於自定義字體。

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]; 

如果你想顯示爲you visits the refrence link here

教程可能對開發這個代碼的幫助。

快樂codeing

感謝和問候 @samuel

0

如果你想使用定製Font..Folow此步驟...

  1. 將字體文件添加到您的資源文件
  2. 編輯您的Info.plist:使用密鑰Fonts provided by application添加新條目。
  3. 對於每一個文件,文件名添加到這個陣列

在下面的例子中,我已經添加字體「幻覺記憶國界單」:

Info.plist: adding custom fonts

在你應用程序可以使用

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 240, 50)]; 

    [label1 setFont: [UIFont fontWithName: @"DejaVuSansMono-Bold" size:14.f]]; 

或者,如果你想在HTML/CSS中使用它,只需要使用font-family:DejaVu Sans Mono;

注意:這是iOS 3.2及更高版本中可用。