Reputation: 8066
It is easy to add left and right buttonbaritem on navigationbar
but I hope to add button navigationbar center
my code is
[self.navigationItem.titleView addSubview:button ];//button is not nil
but nothing happens
Yourc comment welcome
Upvotes: 0
Views: 2136
Reputation: 1136
According to the documentation for UINavigationItem's titleView property, "Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar."
Upvotes: 0
Reputation: 318774
The titleView
is nil
by default so your code doesn't do anything.
Change the code to:
self.navigationItem.titleView = button;
This sets your button as the titleView
.
Upvotes: 1