为什么我的标签栏按钮无法在 iPad 上自动调整大小?

2024-03-29

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

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

我正在以编程方式创建 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 按钮填充视图的整个宽度?

预先非常感谢您的帮助!


Change UITabBar财产itemPositioning to UITabBarItemPositioningFill:

self.tabBar.itemPositioning = UITabBarItemPositioningFill;

斯威夫特版本:

tabBar.itemPositioning = .fill

UITabBar item定位参考 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBar_Class/index.html#//apple_ref/occ/instp/UITabBar/itemPositioning

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么我的标签栏按钮无法在 iPad 上自动调整大小? 的相关文章

随机推荐

  • 可以使用 Flutter 复制 iOS App Store 转换吗?

    是否可以使用Flutter复制iOS App Store的转场效果 我尝试通过将两个标签放入两个小部件的根布局中来使用英雄动画 但动画看起来很卡顿或者不是我所期望的 但这样做的好处是 当我使用 MaterialPageRoute 时 我可以
  • Logger 和 System.out.println 的输出不按顺序

    我想要记录器的输出inputstream在 Eclipse 控制台中 但每次执行的时候 结果的顺序总是不一样 我有几个类 其中一个主类可以调用其他类 并且我将记录器放入每个方法中进行调试 我将结果打印到控制台 我也有检索的方法inputst
  • 在 javascript 中使用 .css() 设置细边框

    因此 当用户单击页面上的按钮时 我试图在按钮周围设置边框 要设置处理程序 我要 reportButtons click function change border color 我尝试了两种方法来更改其中按钮的边框颜色 第一种方法是使用 c
  • Asp.net mvc 表单发布和分页

    我有一个操作方法 搜索 在发布表单时调用该方法 根据表单的发布值 可能有数千个搜索结果 我想逐页显示搜索视图 但如何知道第一次发布的表单值是什么 这样我就可以通过传递页面参数来调用搜索视图 最好的方法是接受系统的无状态性 每次渲染视图时 请
  • 如何将 C# 转换为 C++ [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 有人可以帮我将 C 转换为 C 吗 这是一个例子 using System using System Net using System
  • Google数据存储-在没有热点的情况下对创建日期字段进行索引

    我正在使用 Google Datastore 需要查询它来检索一些实体 这些实体需要按从最新到最旧的顺序排序 我的第一个想法是拥有一个包含时间戳的 date created 属性 然后我会索引该字段并对该字段进行排序 这种方法的问题是它会导
  • 像 Chanel 应用程序一样自定义集合视图布局

    我正在尝试做一个自定义布局 例如香奈儿应用程序 您可以在应用程序商店中找到该应用程序 https itunes apple com us app chanel fashion id409934435 mt 8 https itunes ap
  • 使用 simple_form 和rails 4 创建多个嵌套表单

    我正在尝试使用以下模型创建一个简单的应用程序 类别 has many gt 问题 has many gt 答案 我有以下用于创建类别 问题的代码 categories form haml html simple form for categ
  • 使用 AWK 进行字数统计

    我有如下文件 这是一个示例文件 该文件将用于测试 this is a sample file this file will be used for testing 我想用AWK来统计单词数 预期输出是 this 2 is 1 a 1 sam
  • 为什么 smartmatch 根据操作数的顺序返回不同的值?

    我有一个数组 以下测试返回 true 1 a 然而 以下测试返回 false a 1 我在 学习 Perl 中读到 智能匹配运算符两侧的值的放置并不重要 但显然在上面的代码中它确实如此 这是为什么 这两个语句检查的是不同的东西吗 除了其他答
  • 经典C++(带类的C)的调用/返回功能,哪些现代语言具有它?

    第 57 页C 的设计和演变 https rads stackoverflow com amzn click com 0201543303 Stroustrup 博士谈到了一个最初是 C with Classes 的一部分的功能 但它不是现
  • 混合 C++ 和 Objective-C

    我使用 C 作为应用程序主干 使用 Objective C 作为 GUI 这很好 但是当谈到在 Objective C mm 文件 中将这些代码混合在一起时 我有几个问题 1 我可以将 STL 容器与 Objective C 或 Cocos
  • TabView 内的 SwiftUI iOS 16 NavigationPath 警告:NavigationAuthority

    我有一个TabView每个选项卡都有自己的NavigationPath我正在处理一个ObservableObject MainActor final class Router ObservableObject Published var h
  • 如何通过 ID 以外的其他方式获取 Backbone.js 模型?

    Backbone js 通过 ID 获取模型的默认 RESTful 方法非常简单且直接 但是 我似乎找不到任何通过不同属性获取模型的示例 如何通过不同的属性获取 Backbone js 模型 var Widget Backbone Mode
  • 单个文件中的多个类:此处不允许修饰符 private

    我无法理解为什么这段代码不能编译 class A public static void main String args System out println hi private class B int a 我将内容保存在名为的文件中A
  • Azure ARM 模板嵌套模板部署不会更新资源\无法启动

    我有以下 ARM 模板结构 Parent Template Nested Template 1 Nested Template 6 所以我只有 2 层模板 父级模板和嵌套模板 假设我将父级部署到一个空资源组 一切正常 之后 我删除其中一项资
  • iOS - 通过区域设置更改 UIDatePicker 的语言

    我正在用 Herbrew 语言创建应用程序 iPhone 的语言可以是任何语言 但我的应用程序只能在 Herbrew 中运行 在 iOS 的 UIDatePicker 中 我们有一个属性 locale 它将更改它显示的语言 但在 iOS5
  • Java Swing 保存和加载工作区/设置

    我有一个 Java Swing 应用程序 其中包含一堆框架 而这些框架又主要包含显示大量数据的表格 由于在启动时安排所有窗口和表格总是很麻烦且耗时 因此我想实现 工作区 功能 以便用户可以保存首选项设置并在启动时选择自动将存储的工作区加载到
  • 找到未合并的 Git 分支?

    我有一个包含许多分支的 Git 存储库 其中一些已经合并 一些还没有 由于分支数量相当多 如何判断哪些分支尚未合并 我想避免必须进行 章鱼 合并和重新合并已经合并的分支 尝试这个 git branch merged master 它按照锡上
  • 为什么我的标签栏按钮无法在 iPad 上自动调整大小?

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