我正在构建一个通用的 iOS 应用程序,iPad 版本使用 SplitViewController。在弹出 View 中,我有一个带有两个按钮的 UITabBarController。当它在 iPhone 上运行时,TabBar 按钮会正确拉伸(stretch)以填充 View 的整个宽度...
...但是在 iPad 上,在弹出 View 中,按钮不会拉伸(stretch)以填满整个宽度...
我正在以编程方式创建 UITabBarController...
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...
self.tabBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
...但这也没有用。如何让 UITabBar 按钮填满整个 View 的宽度?
非常感谢您的帮助!
最佳答案
将 UITabBar
属性 itemPositioning
更改为 UITabBarItemPositioningFill
:
self.tabBar.itemPositioning = UITabBarItemPositioningFill;
快速版本:
tabBar.itemPositioning = .fill
关于iphone - 为什么我的 TabBar 按钮不能在 iPad 上自动调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9629135/