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;
[audioB开发者_StackOverflowtn release];
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.
精彩评论