2012-05-18 53 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