UIViewController 标题始终为 (null)
UIViewController title is always (null)
我有这个问题。在我最初的 UIViewController 中,标题始终为空。我试过 [self setTitile:]
和许多其他设置标题的方法,但没有任何效果。我想应该有应用程序名称作为标题,并且它应该设置在 Xcode 中的某个地方?
我是这样设置标题的:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setTitle:@"Your Title"];
//[self setTitle:@"Some title"];
. . .
}
我还在情节提要中为控制器和嵌入它的导航控制器设置了标题,但没有成功。
谢谢。
试试下面的代码..
UILabel *lbl = [[UILabel alloc] initWithFrame:self.navigationController.navigationBar.frame];
lbl.text = @"AppName";
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont systemFontOfSize:18];//18
lbl.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = lbl;
//(或)尝试
self.navigationController.navigationBar.topItem.title = @"AppName";
希望对你有帮助..!
我有这个问题。在我最初的 UIViewController 中,标题始终为空。我试过 [self setTitile:]
和许多其他设置标题的方法,但没有任何效果。我想应该有应用程序名称作为标题,并且它应该设置在 Xcode 中的某个地方?
我是这样设置标题的:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setTitle:@"Your Title"];
//[self setTitle:@"Some title"];
. . .
}
我还在情节提要中为控制器和嵌入它的导航控制器设置了标题,但没有成功。 谢谢。
试试下面的代码..
UILabel *lbl = [[UILabel alloc] initWithFrame:self.navigationController.navigationBar.frame];
lbl.text = @"AppName";
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont systemFontOfSize:18];//18
lbl.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = lbl;
//(或)尝试
self.navigationController.navigationBar.topItem.title = @"AppName";
希望对你有帮助..!