为什么我的TabBar按钮不会在iPad上自动显示? [英] Why don't my TabBar buttons autoresize on the iPad?

查看:139
本文介绍了为什么我的TabBar按钮不会在iPad上自动显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个通用iOS应用程序,iPad版本使用SplitViewController。在popover视图中,我有一个带有两个按钮的UITabBarController。当它在iPhone上运行时,TabBar按钮正确拉伸以填充视图的整个宽度......

I'm building a universal iOS app and the iPad version uses a SplitViewController. In the popover view, I have a UITabBarController with two buttons. When it runs on the iPhone, the TabBar buttons correctly stretch to fill the entire width of the view...

...但在iPad上,在弹出视图中,按钮不会拉伸以填充整个宽度......

...but on the iPad, in the popover view, the buttons don't stretch to fill the entire width...

我正在以编程方式创建UITabBarController ...

I'm creating the UITabBarController programmatically...

InspectionTabBarViewController *inspectionTabBarVC;
    InspectionListViewController *inspectionListVC;
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

        inspectionListVC = [[InspectionListViewController alloc] initWithSunday:NO];
        inspectionListVC.managedObjectContext = self.managedObjectContext;
        UINavigationController *calendarNavVC = [[UINavigationController alloc] initWithRootViewController:inspectionListVC];
        calendarNavVC.title = @"Calendar";

        InspectionMapViewController *mapViewVC = [[InspectionMapViewController alloc] initWithNibName:@"InspectionMapView_iPhone" bundle:nil];
        UINavigationController *mapdNavVC = [[UINavigationController alloc] initWithRootViewController:mapViewVC];
        mapdNavVC.title = @"Map";

        inspectionTabBarVC = [[InspectionTabBarViewController alloc] init];
        [inspectionTabBarVC addChildViewController:calendarNavVC];
        [inspectionTabBarVC addChildViewController:mapdNavVC];
        self.window.rootViewController = inspectionTabBarVC;
    } 
    else 
    {
        inspectionListVC = [[InspectionListViewController alloc] initWithSunday:NO];
        UINavigationController *calendarNavVC = [[UINavigationController alloc] initWithRootViewController:inspectionListVC];
        calendarNavVC.title = @"Calendar";

        InspectionMapViewController *mapViewVC = [[InspectionMapViewController alloc] initWithNibName:@"InspectionMapView_iPad" bundle:nil];
        UINavigationController *mapdNavVC = [[UINavigationController alloc] initWithRootViewController:mapViewVC];
        mapdNavVC.title = @"Map";

        inspectionTabBarVC = [[InspectionTabBarViewController alloc] init];
        [inspectionTabBarVC addChildViewController:calendarNavVC];
        [inspectionTabBarVC addChildViewController:mapdNavVC];

        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        self.splitViewController = [[UISplitViewController alloc] init];
        self.splitViewController.delegate = detailViewController;
        self.splitViewController.viewControllers = [NSArray arrayWithObjects:inspectionTabBarVC, detailNavigationController, nil];

        self.window.rootViewController = self.splitViewController;
        inspectionListVC.detailViewController = detailViewController;
        inspectionListVC.managedObjectContext = self.managedObjectContext;

        detailViewController.detailViewControllerDelegate = inspectionListVC;
    }

    [self.window makeKeyAndVisible];

我还尝试使用以下语句在InspectionTabBarViewController的loadView方法中设置autoResizeMask ...

I also tried setting the autoResizeMask inside the InspectionTabBarViewController's loadView method using the following statement...

self.tabBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;

...但这也不起作用。如何让UITabBar按钮填充视图的整个宽度?

...but that didn't work either. How can I get the UITabBar buttons to fill the entire width of of the view?

非常感谢您的帮助!

推荐答案

UITabBar 属性 itemPositioning 更改为 UITabBarItemPositioningFill

self.tabBar.itemPositioning = UITabBarItemPositioningFill;

Swift版本:

tabBar.itemPositioning = .fill

UITabBar itemPositioning reference

这篇关于为什么我的TabBar按钮不会在iPad上自动显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆