Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4042484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:00:42+00:00 2026-05-20T13:00:42+00:00

I want to add a custom button (to the right) in my navigation bar.

  • 0

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 to the right (where the button is supposed to be), it triggers the function “toggleAudioPlayback”, so the only problem is that I don’t see the button!

I tried with different image, setting a background color, nothing works…

By the way, I use this image somewhere else in the code, and I see it (on a custom button, but not in a navigationBar).

Help me please!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:00:43+00:00Added an answer on May 20, 2026 at 1:00 pm

    Make your life easier and instead of a customView just use a UIBarButtonItem with a custom image:

        UIBarButtonItem *audioBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"play.png"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleAudioPlayback:)];
        self.navigationItem.rightBarButtonItem = audioBtn;
        [audioBtn release];
    

    UPDATE

    Since you have indicated you want your button to not have a border, then you will need to use a CustomView afterall, but I have modified your code to make this work (the key difference is the assigning of the frame, which is set to the size of the image, but you could set it to a custom size to have the image centered):

    UIButton *audioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *playImg = [UIImage imageNamed:@"play.png"];
    [audioButton setBackgroundImage:playImg forState:UIControlStateNormal];
    [audioButton setBackgroundImage:playImg forState:UIControlStateHighlighted];
    audioBtn.frame = CGRectMake(0,0,playImg.size.width,playImg.size.height);
    [audioBtn addTarget:self action:@selector(toggleAudioPlayback:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:audioBtn];
    self.navigationItem.rightBarButtonItem = button;
    [audioBtn release];
    [button release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a custom button bar as described here . Now, I want
I want to add two buttons with custom image to Navigation Bar with some
I want to add a button or custom view on the status bar in
I want add my custom sidebar next right column all page. Please check this
In the tableview the user can tap the upper right button (navigation bar rightside)
iPhone application, which has two buttons -right side- of Navigation Bar title. I want
I'm having an issue with a custom soundcloud button that I want to add
I know xcode don't have radio Button so I try to add a custom
I want to add a custom property to a button in window form. Currently
Have been trying to add a custom button for about 2 hours and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.