2013-01-08 49 views
0

我創建了一個按鈕來設置背景圖片,然後給按鈕添加一個標籤,我嘗試修改標籤中字體的大小但失敗。我不知道如何解決這個問題,請任何人幫助我。如何修改標籤的字體大小

這是我的代碼:

returnButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    returnButton.frame = CGRectMake(10, 9, 50, 28); 

    [returnButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 
    [returnButton setImage:[UIImage imageNamed:@"US MEAT_buttons.png"] forState:UIControlStateNormal]; 
    [returnButton setImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted]; 

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(8, 2, 50, 20)]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.textColor = [UIColor whiteColor]; 
    label.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:10]; 
    label.text = @"返回";//返回means "return" 
    [returnButton addSubview:label]; 
    [label release]; 
+1

因此您的字體STHeiti-Medium.ttc未加載? – Hiren

+0

您必須安裝字體並將其添加到支持字體的plist中。 – Shantanu

回答

1

也許你自定義字體沒有正確補充說:

  1. 將字體文件添加到您的資源文件
  2. 編輯您的Info.plist:添加一個由應用程序提供的關鍵字體的新條目。
  3. 對於每一個文件,文件名添加到這個陣列

    label.font = [UIFont fontWithName:@"STHeiti-Medium" size:10];

如果你想添加自定義字體請檢查下面的答案How to include and use new fonts in iPhone SDK?

+0

非常感謝 –

0

,是要在資源文件夾中,並且您需要將font的詳細信息添加到plist文件中。檢查answer