Tiois
Tiois

Reputation: 1559

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];

Upvotes: 6

Views: 3606

Answers (1)

lxt
lxt

Reputation: 31304

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.

Upvotes: 11

Related Questions