Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I center a UIToolbar item?

I am putting a label on a UIToolbar (per this tip: Adding a UILabel to a UIToolbar).

But the toolbar has a button on the left side, and so flexible spaces throw the label off the center, which is where I'd like it to be. Can I somehow center this toolbar item so that it remains centered in the toolbar?

(Already tried balancing the button with a dummy fixed space, no dice.)

Thanks!

like image 721
Ben Zotto Avatar asked Mar 24 '10 20:03

Ben Zotto


1 Answers

Yes we can center a toolbar item just put two flexible space in the toolbar like :

UIBarButtonItem *flexibaleSpaceBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

toolbar.items = [NSArray arrayWithObjects:loginButton,flexibaleSpaceBarButton,toolBarLabel,flexibaleSpaceBarButton, nil];
like image 167
Kasaname Avatar answered Sep 25 '22 11:09

Kasaname