gsempe
gsempe

Reputation: 5499

UITabBarController UITabBarItems placed on the left but one on the right

I would like to place all UITabBarItems of my UITabBarController on the left but one on the right. Any idea to do it ?

Upvotes: 2

Views: 883

Answers (2)

AnalogKid
AnalogKid

Reputation: 11

I would instantiate a UITabBarItem with nil for title and image and a tag with a value out of range.

UITabBarItem *flexItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:999];

Then add these to your items array to create the effect you wish.

aTabBar.items = @[item1, item2, flexItem, flexItem, item3];

In the tabBar:didSelectItem: callback add a switch case to handle your items and let the flexItem's fall through the default case.

Upvotes: 1

jimmyg
jimmyg

Reputation: 580

You can add a flexible space between the last item on the left and the item on the right.

NSMutableArray *itemArray [[NSMutableArray alloc] init];

// Add items to the left
...

// Add flexible item to push everything else to the right
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] inithWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
        target:nil
        action:nil];
[itemArray addObject:flexItem];
[flexItem release];

// Add items to the right
...

self.toolbarItems = itemArray;
[itemArray release];

Upvotes: 0

Related Questions