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 933173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:47:15+00:00 2026-05-15T20:47:15+00:00

I am trying to add an image to the UIBarButtonItem which I have to

  • 0

I am trying to add an image to the UIBarButtonItem which I have to use in a UIToolbar.

I have managed to read the image and even get it to display with a UIImageView, but when i add it to the UIBarButtonItem and then add that item to the UIToolbar, the toolbar just displaces a “Blank White” space the size and shape of the image that I am trying to load.

here is what I am trying.

UIImage *image = [UIImage imageNamed:@"6.png"];

//This is the UIImageView that I was using to display the image so that i know that it is being read from the path specified.  
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 50, image.size.width, image.size.height);
[self.view addSubview:imageView];

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:image forState:UIControlStateNormal];

//This is the first way that I was trying to accomplish the task but i just get a blank white space

//This is the Second way but with the same blank white result.
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithCustomView:button2];

NSArray *items = [NSArray arrayWithObjects: systemItem1, nil];

//Adding array of buttons to toolbar
[toolBar setItems:items animated:NO];

//Adding the Toolbar to the view.
[self.view addSubview:toolBar];

Your help will be much appreciated.

Thank You!

Shumais Ul Haq

  • 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-15T20:47:15+00:00Added an answer on May 15, 2026 at 8:47 pm

    Other than you’d normally expect in UIKit stuff, you might need to set a frame for the button explicitly. Maybe that’s your problem.

    This is what I wrote for a custom styled back button, as a category to UIBarButtonItem (but you can just take the pieces you need from it).

    Note that this was used for the navigation bar, not the toolbar, but I presume the mechanics are the same, since it is a UIBarButtonItem as well. For UIToolbar you can just use IB to get it right at compile time.

    #define TEXT_MARGIN 8.0f
    #define ARROW_MARGIN 12.0f
    #define FONT_SIZE 13.0f
    #define IMAGE_HEIGHT 31.0f
    
    +(UIBarButtonItem*)arrowLeftWithText:(NSString*)txt target:(id)target action:(SEL)selector
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *img = [[UIImage imageNamed:@"arrow_left.png"]
            stretchableImageWithLeftCapWidth:15 topCapHeight:0];
    
        [btn addTarget:target action:selector forControlEvents:UIControlEventTouchDown];
    
        [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
        [btn setContentEdgeInsets:UIEdgeInsetsMake(0.0f,0.0f,0.0f,TEXT_MARGIN)];
        [btn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:FONT_SIZE]];
        [btn.titleLabel setShadowOffset:CGSizeMake(0.0f,-1.0f)];
    
        /**** this is the magic line ****/
        btn.frame = CGRectMake(0.0f,0.0f,
            [txt sizeWithFont:[btn.titleLabel font]].width+ARROW_MARGIN+TEXT_MARGIN,
            IMAGE_HEIGHT);
    
        [btn styleBarButtonForState:UIControlStateNormal withImage:img andText:txt];
        [btn styleBarButtonForState:UIControlStateDisabled withImage:img andText:txt];
        [btn styleBarButtonForState:UIControlStateHighlighted withImage:img andText:txt];
        [btn styleBarButtonForState:UIControlStateSelected withImage:img andText:txt];
        return [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
    }
    

    usage:

    [UIBarButtonItem arrowLeftWithText:@"Back" target:self action:@selector(dismiss)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add the image on to the UIBarButtonItem .But it is
I'm trying to add an arrow image to my link and have it positioned
I'm trying to add an image as svn:externals but TortoiseSVN refuses it somehow. Currently
I am making an application in which i am trying to add an image
I am trying to add a image to a RTF document which I am
I am Trying to add an image to an existing button..I have done that
I am trying to add background image for the . but It is not
Friends, i m trying add image to my Jbutton using seticon method but it
I am trying to add an image into a document using WordML. I have
Hi I'm trying to add my image name to my database, I have a

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.