I want to add a custom button (to the right) in my navigation bar.
I have the following code in my viewDidLoad function:
UIButton *audioBtn = [[UIButton alloc] init]; [audioBtn setTitle:@"Play" forState:UIControlStateNormal]; UIImage *buttonImage = [UIImage imageNamed:@"play.png"]; [audioBtn setBackgroundImage:buttonImage forState:UIControlStateNormal]; [audioBtn addTarget:self action:@selector(toggleAudioPlayback:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:audioBtn]; self.navigationItem.rightBarButtonItem = button; [audioBtn release]; [button release];
I can’t see the button in my navigation bar, but if I click on the right (where the button should be), it launches the “toggleAudioPlayback” function, so the only problem is that I don’t see the button!
I tried with a different image, setting the background color, nothing works ...
By the way, I use this image somewhere else in the code, and I see it (on the user button, but not in the navigationBar).
Help me please!
source share