0

我有这个代码来显示按钮作为导航栏的标题,然后在按钮代码中我编写代码来更改取消按钮文本标签的字体。但我没有使用下面的代码获得正确的字体版本。

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 georgia,但我没有得到正确的字体谢谢。

4

3 回答 3

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;
于 2012-05-18T10:29:22.853 回答
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;

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

于 2012-05-18T10:48:23.557 回答
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,根据您的需要调整代码应该不会太难。

祝你好运 !

于 2012-05-18T10:44:45.133 回答