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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:27:09+00:00 2026-06-17T13:27:09+00:00

I am creating a bar button in all classes. Is there anyway to write

  • 0

I am creating a bar button in all classes. Is there anyway to write this code only once and be used in all classes?

 toolbar = [[UIToolbar alloc]
               initWithFrame:CGRectMake(90, 0, 100, 45)];
    toolbar.tintColor=self.navigationController.navigationBar.tintColor;

    // create an array for the buttons
    NSMutableArray* buttonsArray = [[NSMutableArray alloc] initWithCapacity:2];

    // create a standard save button

    UIImage *buttonImage = [UIImage imageNamed:@"home.png"];

    UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [homeButton setImage:buttonImage forState:UIControlStateNormal];


    homeButton.frame = CGRectMake(100,2, 35, 35);

    [homeButton addTarget:self action:@selector(homeButtonpress) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *customHomeBarItem = [[UIBarButtonItem alloc] initWithCustomView:homeButton];

    [buttonsArray addObject:customHomeBarItem];
    [customHomeBarItem release];


    UIImage *logoutImg=[UIImage imageNamed:@"power.png"];

    UIButton *logOutBtn=[UIButton buttonWithType:UIButtonTypeCustom];

    [logOutBtn setImage:logoutImg forState:UIControlStateNormal];

    [logOutBtn addTarget:self action:@selector(logOutButtonPress) forControlEvents:UIControlEventTouchUpInside];


    logOutBtn.frame=CGRectMake(0, 2, 35, 40);


    UIBarButtonItem *customLogOutButton=[[UIBarButtonItem alloc]initWithCustomView:logOutBtn];

    [buttonsArray addObject:customLogOutButton];
    [customLogOutButton release];


    [toolbar setItems:buttonsArray animated:NO];
    [buttonsArray release];

    // place the toolbar into the navigation bar
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
    [toolbar release];
  • 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-06-17T13:27:10+00:00Added an answer on June 17, 2026 at 1:27 pm
    1. Create a Utility class
    2. Add class method for creating & returning UIBarButtonItem.
    3. Import Utility.h in .pch or in classes where you want to use it.

    Utility.m

    + (UIBarButtonItem *) barButtonItemWithTitle:(NSString *)title backgroundImage:(NSString *)image target:(id)target action:(SEL)action
    {
        //create button & return it
        return barButtonItem;
    }
    

    To use

    ViewController.m

        UIBarButtonItem* backButtonItem = [Utility barButtonItemWithTitle:@" Back" backgroundImage:@"back_button" target:self action:@selector(backButtonAction)];
        self.navigationItem.leftBarButtonItem = backButtonItem;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a stacked bar chart just like this one . Notice that the
My goal is to create non-white toolbar bar items. I have tried creating with
I am creating a vertical button bar with 3 buttons. How do I force
I am creating a split-view iPad application. When the user presses the bar button
I'm creating an action bar on ICS. Due to spacing only the icons are
When creating a titlebar with a button, which is common in all activities e.g.
When creating a titlebar with a button, which is common in all activities e.g.
I am creating a tab bar application, but i want to create tab bar
I am creating a Tab Bar Controller xib file that will house the tab
I am working on creating a progress bar for ffmpeg in java. So for

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.