隐藏导航栏标题

发布于 2024-11-18 22:14:54 字数 182 浏览 1 评论 0原文

我的第一个视图名为“返回”。我需要隐藏导航栏的标题,因为我有自定义导航栏。

我尝试使用这段代码,但没有成功!

self.title = @"back";
self.navigationController.navigationItem.titleView.hidden = YES;

my first view named "back". I need to hidden the title of the navigationbar because I have my custom navigation bar.

I try with this code but it didn't work!

self.title = @"back";
self.navigationController.navigationItem.titleView.hidden = YES;

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

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

发布评论

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

评论(5

转身泪倾城 2024-11-25 22:14:54

刚刚面临同样的问题,并正在做:

self.title = @"YourTitle";
self.navigationItem.titleView = [[UIView alloc] init];

成功了。下一个视图将具有标有 YourTitle 的后退按钮,但在第一个视图中,不会显示标题。

Just faced the same issue, and doing:

self.title = @"YourTitle";
self.navigationItem.titleView = [[UIView alloc] init];

Did the trick. The next view will have the back button labeled with YourTitle but in the first one, the title won't be shown.

丑丑阿 2024-11-25 22:14:54

如果你想隐藏整个导航栏并且想使用自己的导航栏,你可以先隐藏导航控制器的导航栏。

[self.navigationController setNavigationBarHidden:YES];

或者,如果您只想隐藏标题,您可以这样做

self.title = @"";

,或者如果您已使用导航栏的自定义标题视图,您可以这样做

self.navigationItem.titleView.hidden = YES;

,或者如果您想隐藏后栏按钮项目,您可以这样做

self.navigationItem.hidesBackButton = TRUE;

If you want to hide entire navigation bar and if you want to use your own navigation bar, you can first hide navigation controller's navigation bar.

[self.navigationController setNavigationBarHidden:YES];

or if you want to only hide title you can do

self.title = @"";

or if you have used custom title view for navigation bar, you can do

self.navigationItem.titleView.hidden = YES;

or if you want to hide back bar button item, you can do

self.navigationItem.hidesBackButton = TRUE;
多孤肩上扛 2024-11-25 22:14:54

遇到同样的问题,我只是创建一个假 UIView 来填充 titleView 属性并隐藏它:

UIView *fakeTitleView = [[UIView alloc] init];
fakeTitleView.hidden = YES;
[self.navigationItem setTitleView:fakeTitleView];
[fakeTitleView release];

希望它能有所帮助。

Having the same issue, I just create a fake UIView to populate the titleView property and hide it :

UIView *fakeTitleView = [[UIView alloc] init];
fakeTitleView.hidden = YES;
[self.navigationItem setTitleView:fakeTitleView];
[fakeTitleView release];

Hope it could help.

苦笑流年记忆 2024-11-25 22:14:54

保留后退按钮的另一个选项:

[self.navigationController.navigationBar setTitleTextAttributes:@{
    NSForegroundColorAttributeName : [UIColor clearColor]
}];

Another option which preserves the back button:

[self.navigationController.navigationBar setTitleTextAttributes:@{
    NSForegroundColorAttributeName : [UIColor clearColor]
}];
三五鸿雁 2024-11-25 22:14:54

Swift

self.navigationItem.title = "your title" // So title shows nav "back" button
self.navigationItem.titleView = UIView() // To hide the title on this View Controller

我把它放在 viewWillAppear

Swift

self.navigationItem.title = "your title" // So title shows nav "back" button
self.navigationItem.titleView = UIView() // To hide the title on this View Controller

I put this in viewWillAppear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文