Reputation: 11672
I have 3 tab bar items, I want them to show like this in tab bar:
| |
| 1 2 3 |
| |
I see this property in InterfaceBuilder:
I have tried all cases, but it doesn't work, it shows something like this:
| |
| 1 2 3 |
| |
Upvotes: 2
Views: 11699
Reputation: 139
The accepted answer requires tabBar.itemPositioning to be set in order for it to work. If the above answer does not work, try setting it to .centered. Thereafter, you should be able to programmatically set the item spacing.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.tabBar.itemPositioning = .centered
self.tabBar.itemSpacing = UIScreen.main.bounds.width / 6
}
Upvotes: 1
Reputation: 175
Here's the code for Objective-C.
-(void)viewDidLoad
{
[super viewDidLoad];
[self.tabBar setItemPositioning:UITabBarItemPositioningFill];
}
You can also set the value in the Storyboard on the Tab Bar
Upvotes: 1
Reputation: 61
Well, here is a universal solution, without any hard coded values.
In the viewDidLoad()
of your UITabBarController
, set
tabBar.itemPositioning = .fill
Upvotes: 4
Reputation: 11672
Here is simplest solution:
If you have a sub TabBarController, add this code in viewDidLayoutSubviews
, it works for me.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.tabBar.itemSpacing = UIScreen.main.bounds.width / 6
}
Upvotes: 1