如何均匀设置UITabBarItem宽度以占据所有Tab Bar [英] How to set UITabBarItem widths evenly to take up all of Tab Bar

查看:20
本文介绍了如何均匀设置UITabBarItem宽度以占据所有Tab Bar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like the tab bar items in my app to evenly take up all of the tab bar whether in portrait or landscape. I have five tabs on my tab bar. The code below does not accomplish this. What am I doing wrong? I noticed that the screenSize.size.height actually references the width and I am not sure why that is.

非常感谢任何帮助.

谢谢

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

tabBar.itemPositioning = .fill

希望这对某人有所帮助.

Hope this helps someone out.

这篇关于如何均匀设置UITabBarItem宽度以占据所有Tab Bar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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