Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center a button in a navigationBar

I would like to center a button in my navigationBar, which is currently defined as a rightBarButtonItem :

UIBarButtonItem *audioBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(toggleAudioPlayback:)];
self.navigationItem.rightBarButtonItem = audioBtn;
[audioBtn release];
like image 660
Tiois Avatar asked Mar 08 '11 01:03

Tiois


1 Answers

You can use the .titleView property of your navigation item - but you'll need to create your own assets for this (you won't be able to use a UIBarButtonItem). From Apple's docs:

...(titleViews) can contain buttons. Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar. Custom title views are centered on the navigation bar and may be resized to fit.

like image 146
lxt Avatar answered Sep 29 '22 00:09

lxt