madmax
madmax

Reputation: 1813

How to add a simple button to the middle of a navigation bar?

i found a lot of topics around placing buttons on navigation bar but none showed me how to place a button at the center of the bar. I found an example with a segmented control but i don't need that.

Just a button instead of the title. Is that possible? ;-)

Edit:

That will do it:

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[titleButton setFrame:CGRectMake(0, 0, 170, 35)];
self.navigationItem.titleView = titleButton;

Upvotes: 19

Views: 8396

Answers (1)

Vladimir
Vladimir

Reputation: 170829

You can set any custom view (e.g. UIButton) as a titleView property to your current navigationItem - that should do the trick.

Upvotes: 23

Related Questions