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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:21:37+00:00 2026-06-14T21:21:37+00:00

I wanted to make my right bar button contain 2 buttons. So I did

  • 0

I wanted to make my right bar button contain 2 buttons. So I did that by using a UIToolbar. But the problem is that the 2 buttons sit apart from each other, while the affect I would like to achieve is too have them sitting flush against each other.

Here is an image of how they look now

enter image description here

Here is the code I use to achieve the buttons so far

    UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 2.0f, 120.0f, 40.01f)]; // 44.01 shifts it up 1px for some reason
tools.clearsContextBeforeDrawing = NO;
tools.clipsToBounds = YES;
tools.tintColor = [UIColor blueColor];
tools.barStyle = -1;// -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];


UIButton * upButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
upButton.frame = CGRectMake(0, 07, 46, 30);
upButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
[upButton setTitle:@"" forState:UIControlStateNormal];
upButton.backgroundColor = [UIColor clearColor];
[upButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
[upButton addTarget:self action:@selector(pageDown) forControlEvents:UIControlEventTouchUpInside];
[upButton setBackgroundImage:[UIImage imageNamed:@"page_up.png"] forState:UIControlStateNormal];
[upButton setBackgroundImage:[UIImage imageNamed:@"page_up_action.png"] forState:UIControlStateSelected];
UIBarButtonItem *toggleSegmentedControlBarItemOne = [[UIBarButtonItem alloc] initWithCustomView:upButton];
[buttons addObject:toggleSegmentedControlBarItemOne];

UIButton * downButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
downButton.frame = CGRectMake(0, 07, 46, 30);
downButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
[downButton setTitle:@"" forState:UIControlStateNormal];
downButton.backgroundColor = [UIColor clearColor];
[downButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
[downButton addTarget:self action:@selector(pageUp) forControlEvents:UIControlEventTouchUpInside];
[downButton setBackgroundImage:[UIImage imageNamed:@"page_down.png"] forState:UIControlStateNormal];
[downButton setBackgroundImage:[UIImage imageNamed:@"page_down_action.png"] forState:UIControlStateSelected];
UIBarButtonItem *toggleSegmentedControlBarItemTwo = [[UIBarButtonItem alloc] initWithCustomView:downButton];
[buttons addObject:toggleSegmentedControlBarItemTwo];

[tools setItems:buttons animated:NO];

[buttons release];
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
[twoButtons release];

Can anybody please advise me how to get those two buttons to sit beside each other without any gap?

Many Thanks,
-Code

  • 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-14T21:21:39+00:00Added an answer on June 14, 2026 at 9:21 pm

    You can add UISegmentedControl as customView to your navigationItem and set its momentary property to true, that way you will get exactly what you want.

    Here is sample code

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        self.title = @"Test";
    
        UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 90, 30)];
        segControl.momentary = YES;
        segControl.segmentedControlStyle = UISegmentedControlStyleBar;
        segControl.tintColor = [UIColor darkGrayColor];
    
        [segControl insertSegmentWithImage:[UIImage imageNamed:@"up.png"] atIndex:0 animated:NO];
        [segControl insertSegmentWithImage:[UIImage imageNamed:@"down.png"] atIndex:1 animated:NO];
    
        [segControl addTarget:self action:@selector(segButtonDown:) forControlEvents:UIControlEventValueChanged];
    
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:segControl];
    
    }
    
    - (void)segButtonDown:(id)sender {
    
        UISegmentedControl *segControl = (UISegmentedControl *)sender;
    
        switch (segControl.selectedSegmentIndex) {
            case 0:
                NSLog(@"Up");
                break;
            case 1:
                NSLog(@"Down");
            default:
                break;
        }
    
    }
    

    And here is image how it looks like.

    Screenshot

    And here you can see events in console.

    2012-11-25 16:03:47.805 test2[13886:c07] Up
    2012-11-25 16:03:48.367 test2[13886:c07] Down
    2012-11-25 16:03:48.930 test2[13886:c07] Up
    2012-11-25 16:03:49.538 test2[13886:c07] Down
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to make a dictionary using BST but I did not have any
I have been using SharpSVN and love it but I wanted to make sure
I believe I am doing this right but wanted to make sure. In a
I wanted to make a UITableView with text that is both right-aligned and indented
I wanted to make a JOptionPane.showOptionDialog with some JTextArea and JLabel . The problem
I wanted to make a basic custom keypad for the iPhone , I did
I wanted to make an application that will take either the path of the
I wanted to make a function that populates a Grid in WPF with pictures.
I wanted to make a button which is transparent until the user hovers over
I wanted to make sure I'm going about this the right way. I'm designing

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.