ios - 如何均匀设置 UITabBarItem 宽度以占据所有 Tab Bar

标签 ios xcode uitabbarcontroller

我希望我的应用程序中的选项卡栏项目能够均匀地占据所有选项卡栏,无论是纵向还是横向。我的标签栏上有五个标签。下面的代码没有完成这个任务。我究竟做错了什么?我注意到 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

希望这可以帮助别人。

关于ios - 如何均匀设置 UITabBarItem 宽度以占据所有 Tab Bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711237/

相关文章:

iphone - 如何在iOS模拟器中测试UI Interpolating Motion Effect?

ios - 当全局变量的值发生变化时如何启动方法?

objective-c - Xcode - 如何通过命令行更改文件的目标成员身份?

xcode - iOS:如何分发 "parallel"应用程序版本以进行临时 Beta 测试

ios - 为什么我的 UITableview Y 原点会根据 TabBarController 中的位置发生变化

iphone - 选项卡式导航 View 的正确设计模式?

iphone - MkMapView 在触摸时放下别针

iphone - 识别 iPhone 上的移动网络状态

ios - 警告 : Attempt to present * on * which is already presenting (null)

iphone - 导航栏应用程序崩溃