更改 UINavigationBar 中的文本颜色

发布于 2024-09-15 15:46:59 字数 199 浏览 3 评论 0原文

我以前见过这个问题,并找到了如何以简单的方式做到这一点的答案。但是......当我转到推送到视图堆栈上的后续视图时,手动设置 titleView 不起作用。 titleView 视图被推到右侧,而后退按钮及其文本占据 UI 的左半部分。

有没有标准的方法来做到这一点?我注意到 Gowalla 应用程序显然做得很好。我尝试了多种方法,包括类别、子类等,但没有任何运气。

I've seen this question asked around before, and found an answer for how to do this in a simple view. But... when I go to a subsequent view pushed onto the view stack, manually setting the titleView doesn't work out. The titleView view gets pushed off to the right while the back button and its text take over the left half of the UI.

Is there a standard way to do this? I've noticed the Gowalla app apparently does it quite well. I've tried a multitude of approaches including categories, subclasses, etc and haven't had any luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不及他 2024-09-22 15:46:59

每个UIViewController都有它自己的navigationItem,它(可能)有一个titleView。当您在导航控件中推送和弹出视图控制器时,navigationItem 的部分就是您所看到的内容。如果您想要自定义标题颜色,您可以很容易地在每个视图控制器中执行如下操作。

- (UINavigationItem *)navigationItem
{
    UINavigationItem *navigationItem = [super navigationItem];
    UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 44.0f)];
    customLabel.text = @"My Title";
    customLabel.textColor = [UIColor purpleColor];
    navigationItem.titleView = customLabel;
    [customLabel release];
    return navigationItem;
}

Every UIViewController has it's own navigationItem, which (potentially) has a titleView. When you push and pop view controllers in a navigation control, the parts of the navigationItem are what you are seeing. If you wanted a custom title color, you could very easily do something like the following in each of your view controllers.

- (UINavigationItem *)navigationItem
{
    UINavigationItem *navigationItem = [super navigationItem];
    UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 44.0f)];
    customLabel.text = @"My Title";
    customLabel.textColor = [UIColor purpleColor];
    navigationItem.titleView = customLabel;
    [customLabel release];
    return navigationItem;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文