Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何均匀设置UItabaritem宽度以占据所有选项卡栏_Ios_Xcode_Uitabbarcontroller - Fatal编程技术网

Ios 如何均匀设置UItabaritem宽度以占据所有选项卡栏

Ios 如何均匀设置UItabaritem宽度以占据所有选项卡栏,ios,xcode,uitabbarcontroller,Ios,Xcode,Uitabbarcontroller,我希望我的应用程序中的标签栏项目均匀地占据所有标签栏,无论是纵向还是横向。我的标签栏上有五个标签。下面的代码无法实现这一点。我做错了什么?我注意到screenSize.size.height实际上是指宽度,我不知道为什么 非常感谢您的帮助 多谢各位 UITabBar *tabBar = self.tabBarController.tabBar; CGRect screenSize = [[UIScreen mainScreen] bounds]; float width; if (self

我希望我的应用程序中的标签栏项目均匀地占据所有标签栏,无论是纵向还是横向。我的标签栏上有五个标签。下面的代码无法实现这一点。我做错了什么?我注意到screenSize.size.height实际上是指宽度,我不知道为什么

非常感谢您的帮助

多谢各位

UITabBar *tabBar = self.tabBarController.tabBar;

CGRect screenSize = [[UIScreen mainScreen] bounds];

float width;

if (self.isShowingLandscapeView){
    width  = screenSize.size.height/5;
}
else {
    width  = (screenSize.size.width/5);
}

[tabBar setItemWidth:width];
viewDidLoad()
中,设置

tabBar.itemPositioning=.fill


希望这能帮助别人。

在故事板文件的选项卡栏属性检查器中。将“项目定位”属性更改为“居中”。将显示两个字段“项目宽度”和“项目间距”。在“项目间距”旁边选择“自定义”,然后输入满足间距要求的值。希望有帮助。

在Swift 4中,您还可以在
viewDidLoad
方法中输入以下内容


tabBar.alignment=.justized

您不需要做任何事情,选项卡栏项目应自动调整为相等的宽度。对,但我希望5个选项卡栏项目均匀地占据整个选项卡栏。默认情况下,这不会发生。真的吗?你能附上一张截图吗?我一定是误解了你的要求。这里有一个我从另一个帖子中谈论的例子:!在示例代码中,为什么在横向中将屏幕高度除以5?旋转设备时屏幕高度值是否不变?你试过在两个方向上都除以宽度吗?