当视图位于栏上时为 UITabBar 设置单独的标题与更多...?

发布于 2024-08-19 13:42:14 字数 384 浏览 1 评论 0原文

在线程“有没有办法为 UITabBar 设置单独的短标题?”提出这个问题(已编辑):“如何为视图提供短名称以显示在选项卡栏上,以及在链接同一视图时提供更长(更具描述性)的名称到表视图(有更多空间)。”答案是为导航控制器和 tabBar 控制器提供单独的标题。我认为这并不能完全回答问题。有两个地方可以看到tabBar标题:在选项卡栏本身和“更多...”屏幕上,这是一个tableView。

当在选项卡栏上可见时,标题需要较短,但在“更多”视图上时,标题需要较长。达到这个目的有什么技巧呢?

In the thread "Is there a way to set a separate short title for UITabBar?" this question is asked (edited): "How do I give views short names for display on the tab bar, and longer (more descriptive) names when the same view is linked to in a table view (which has more space)." The answers were to give separate titles to the navigation controller and the tabBar controllers. I don't think that completely answers the question. There are two places the tabBar title is seen: on the tab bar itself and on the "More..." screen which is a tableView.

When visible on the tab bar the title needs to be short, but when on the More view the title needs to be longer. What's the trick to accomplish that?

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

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

发布评论

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

评论(1

月光色 2024-08-26 13:42:14

回答我自己的问题:在 UITabBarController delgate 中使用暴力:

// UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
    if ( changed ) { // swap tabBar titles for the controllers with long and short names
        int index = 0; // 0, 1, 2, 3 are on the tab bar, others are on the More tableView
        for ( UINavigationController *aNavController in viewControllers ) {
            if ( index > 3 ) { // use long names, look for short names
                if ( [aNavController.tabBarItem.title ieq:@"Short"] ) {
                    aNavController.tabBarItem.title = @"The Long Title";
                }
            } else { // use short names, look for long names
                if ( [aNavController.tabBarItem.title ieq:@"The Long Title"] ) {
                    aNavController.tabBarItem.title = @"Short";
                }
            }
            index++;
        }
    }
}

Answering my own question: use brute force in the UITabBarController delgate:

// UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
    if ( changed ) { // swap tabBar titles for the controllers with long and short names
        int index = 0; // 0, 1, 2, 3 are on the tab bar, others are on the More tableView
        for ( UINavigationController *aNavController in viewControllers ) {
            if ( index > 3 ) { // use long names, look for short names
                if ( [aNavController.tabBarItem.title ieq:@"Short"] ) {
                    aNavController.tabBarItem.title = @"The Long Title";
                }
            } else { // use short names, look for long names
                if ( [aNavController.tabBarItem.title ieq:@"The Long Title"] ) {
                    aNavController.tabBarItem.title = @"Short";
                }
            }
            index++;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文