Reputation: 57
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];
Upvotes: 2
Views: 3102
Reputation: 1314
In Swift 4 you can also enter the following in viewDidLoad
method
tabBar.alignment = .justified
Upvotes: 1
Reputation: 305
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.
Upvotes: 0
Reputation: 61
In your viewDidLoad()
, set
tabBar.itemPositioning = .fill
Hope this helps someone out.
Upvotes: 2