Gytis
Gytis

Reputation: 670

Center a button on a UIToolBar

I need to center the B item with respect to the toolbar. I create the following in the interface builder:

Item B in the center

It works fine until I dynamically insert additional items:

Item B not in the center

How can I maintain the centralized position of the B item? One idea was to use the Fixed Space Bar Button Items, but I couldn't, because the length of the toolbar changes as well (for different orientations).

Upvotes: 4

Views: 1299

Answers (1)

Rodrigo
Rodrigo

Reputation: 12693

You can use this every time the tab bar change the size:

//lets be tabBar the big view and buttonB the.. well, button B
[buttonB setCenter:CGPointMake(tabBar.frame.size.height/2, tabBar.frame.size.width/2);

Upvotes: 1

Related Questions