我想更改导航栏标题的字体和颜色,我从调色板中拖动到故事板中(不是使用nag控制器+推送segue自动创建的)。 我已经尝试了
self.navigationController.topViewController.title = @"title";
self.title = @"title";
self.navigationItem.title = @"title";
但它们都不起作用。没有标题显示,所以我甚至没有尝试任何字体或颜色的更改。 我该怎么办?
答案 0 :(得分:1)
确保导航栏是某个navigationController的一部分。
试试这个:
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setBackgroundImage: [UIImage imageNamed:@"NavBarColor"] forBarMetrics: UIBarMetricsDefault];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
self.title = @"Title here!";
否则:
UILabel* titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 170.0f, 44.0f)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor colorWithRed: 0.922f green: 0.925f blue: 0.973f alpha: 1.0f];
titleLabel.font = [Utils helveticaBoldFontOfSize: 19.333f];
titleLabel.text = NSLocalizedString(@"Title Here", nil);
self.navigationItem.titleView = titleLabel;