How to set UITabBarItem widths evenly to take up all of Tab Bar

瘦欲@ 提交于 2019-12-08 02:29:40

问题


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.

Any help is much appreciated.

Thank you

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];

回答1:


In your viewDidLoad(), set

tabBar.itemPositioning = .fill

Hope this helps someone out.




回答2:


In Swift 4 you can also enter the following in viewDidLoad method

tabBar.alignment = .justified




回答3:


In the tab bar attribute inspector in your story board file. Change the item positioning property to centered. Two fields additional fields item width and item spacing will appear. next to item spacing select custom and enter a value that satisfies your spacing requirement. Hope that helps.



来源:https://stackoverflow.com/questions/27711237/how-to-set-uitabbaritem-widths-evenly-to-take-up-all-of-tab-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!