0

我有以下内容:

头文件

 UINavigationBar *navigationBar;
  UINavigationItem *navigationItem;

实现文件:在viewDidLoad方法中我尝试了这些:

self.navigationBar.topItem.title = @"title text";

还有这个:

  self.navigationItem.title = @"MyTitle";
  [self.navigationBar pushNavigationItem:navigationItem animated:NO];

但是黑色的条上似乎没有标题:

在此处输入图像描述

有人知道吗?谢谢! 编辑在此处输入图像描述

4

2 回答 2

3
  1. 你应该在你的类属性中定义:

    @property (nonatomic, assign) IBOutlet UINavigationBar *navigationBar;

  2. 您应该将该类设置为File's Owner.

  3. 您应该将导航栏与1中的属性连接起来。 (使用 IBOutlet)
  4. 现在您可以使用以下方法设置其标题:self.navigationBar.topItem.title = @"title text";
于 2011-09-21T12:14:50.883 回答
1

试试这个:-

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = [dataItem objectForKey:@"title"];
[label release];
于 2011-09-21T13:19:35.390 回答