我想更改我从调色板拖到 Storyboard中的导航栏标题的字体和颜色(不是使用 nag Controller + 推送 segue 自动创建的)。 我已经试过了
self.navigationController.topViewController.title = @"title";
self.title = @"title";
self.navigationItem.title = @"title";
但它们都不起作用。没有显示标题,所以我什至没有尝试更改字体或颜色。 我该如何解决?
最佳答案
确保导航栏是某些导航 Controller 的一部分。
试试这个:
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;
关于ios - 更改 Storyboard中拖动的导航栏的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21369696/