ios - 更改 Storyboard中拖动的导航栏的标题

标签 ios objective-c uinavigationbar

我想更改我从调色板拖到 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/

相关文章:

ios - CSS 变换旋转图像不在 Safari 中显示

ios - 如何将数据从自定义 url 方案传递到 SwiftUI 中的 View ?

ios - UITextField 文本未保存

ios - 仅更改默认 backBarButtonItem 的位置

ios - 如何设置视频大小,使其适用于所有没有黑边的 iOS 设备

android - 通过 Xamarin 和 C# 使用和构建第 3 方控件

ios - iOS 中的 JT 日历

ios - ios中的日期转换问题

iphone - 如何向 iPhone RSS 阅读器应用添加刷新按钮?

javascript - 导航栏表现奇怪