2012-05-18 58 views
0

我使用此代碼將按鈕顯示爲導航欄的標題,然後在按鈕代碼中編寫代碼以更改解除壓縮文本標籤的字體。但是我沒有得到正確的字體版本與下面的代碼。更改UINavigationBar標題的字體

UIButton *titleButton = [[UIButton alloc]init]; 
titleButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[titleButton setFrame:CGRectMake(0, 0, 170, 35)]; 
[titleButton setTitle:[NSString stringWithFormat:@"%@ %@",delegatee.selectedBook,delegatee.selectedChapter]forState:UIControlStateNormal]; 

titleButton.titleLabel.font =[UIFont fontWithName:@"Georgia" size:10.0f]; 
[titleButton addTarget:self action:@selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.titleView = titleButton; 

iput格魯吉亞,但我沒有得到正確的字體 感謝。

回答

0

試試這個

的按鈕: - use in Navigation Title view , this is work IOS 4 and IOS 5,我用.....

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];  
[titleButton setFrame:CGRectMake(0, 0, 170, 35)]; 
[titleButton setTitle:@"dee"forState:UIControlStateNormal]; 

UIFont *font=[UIFont fontWithName:@"A_Nefel_Sereke" size:21]; 
titleButton.titleLabel.font =font; 

titleButton.titleLabel.textColor = [UIColor redColor]; 
[titleButton addTarget:self action:@selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.titleView = titleButton; 

我覺得你在你的字體名有問題...請檢查

+0

查看我的更新回答 – Deepesh

+0

如果認爲你有字體問題,請檢查你的項目中的字體名稱 – Deepesh

1

試試這個:

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];  
[titleButton setFrame:CGRectMake(0, 0, 170, 35)]; 
[titleButton setTitle:[NSString stringWithFormat:@"%@ %@",delegatee.selectedBook,delegatee.selectedChapter]forState:UIControlStateNormal]; 

titleButton.titleLabel.font =[UIFont fontWithName:@"Georgia" size:10.0f]; 
[titleButton addTarget:self action:@selector(ClickbtnChaperselection:)forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.titleView = titleButton; 
+0

它不工作。感謝 – stackiphone

+0

當我把標籤,而不是按鈕,它改變了字體。 – stackiphone

0

你爲什麼不只是把一個標籤,而不是一個按鈕的標題?

下面是一個標題標籤代碼:

UILabel *titleView = (UILabel *)self.navigationItem.titleView; 
if (!titleView) 
    { 
    titleView = [[UILabel alloc] initWithFrame:CGRectZero]; 
    [titleView setBackgroundColor:[UIColor clearColor]]; 
    [titleView setFont:[UIFont fontWithName:@"Georgia" size:10.0f]]; 

    [self.navigationItem setTitleView:titleView]; 
    [titleView release]; 
    } 
titleView.text = title; 

如果你需要它的UIButton,它不應該是太難的代碼調整您的需求。

祝你好運!

+0

haii,因爲我需要點擊標題的動作。但我把標籤和嗆,但它也沒有改變uifont – stackiphone

+0

我已經試過這個。 – stackiphone