我有以下内容:
标题文件:
UINavigationBar *navigationBar;
UINavigationItem *navigationItem;
实施文件:
在viewDidLoad
方法中我尝试了这些:
self.navigationBar.topItem.title = @"title text";
还有这个:
self.navigationItem.title = @"MyTitle";
[self.navigationBar pushNavigationItem:navigationItem animated:NO];
但是在黑色栏上似乎没有标题出现:
http://i52.tinypic.com/141l99z.png
有人有什么想法吗?谢谢! 的修改: http://i55.tinypic.com/1zp38kk.png
答案 0 :(得分:3)
您应该在您的类属性中定义:
@property (nonatomic, assign) IBOutlet UINavigationBar *navigationBar;
您应该将该课程设为File's Owner
。
self.navigationBar.topItem.title = @"title text";
答案 1 :(得分: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];