开发者

Setting a separate title for UITabBar when the view is on the bar vs. More...?

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 whi开发者_JAVA技巧ch 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?


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++;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜