joec
joec

Reputation: 3543

Add a UIButton to UINavigationController programmatically

In Interface Builder you can drag a UIButton to the centre of a Navigation Controller, between the rightButtonItem and leftButtonItem.

I would like to do this programmatically, as i am not loading a xib.

I tried:

[self.navigationItem addSubview:myButton] // no luck
[self.navigationController.navigationBar addSubview:myButton] //no luck

Thanks

Upvotes: 0

Views: 789

Answers (1)

nevan king
nevan king

Reputation: 113777

Set the titleView of the UINavigationItem for the view controller you want the button to appear with.

[myAddedViewController.navigationItem setTitleView:myButton]

Upvotes: 1

Related Questions