更改UINavigationBar标题的字体

时间:2012-05-18 10:25:38

标签: iphone ios5 uibutton uinavigationbar uifont

我有这个代码将按钮显示为导航栏的标题,然后在按钮代码中我编写代码来更改解开文本标签的字体。但是我没有得到正确的字体版本下面的代码。

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;

输入格鲁吉亚但我没有得到正确的字体 感谢。

3 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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,根据您的需要调整代码应该不会太难。

祝你好运!

答案 2 :(得分: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;

我认为您的字体名称有问题...请检查

相关问题