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

  • Home
  • SEARCH
  • 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 6186025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:49:01+00:00 2026-05-24T01:49:01+00:00

How do I add UISegmentedControl in UINavigationItem ? I want to create a UINavigationBar

  • 0

How do I add UISegmentedControl in UINavigationItem?
I want to create a UINavigationBar with segment control which add in title of navigation bar.

UISegmentedControl has two indexes.

Here’s what I have:

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:[UIImage imageNamed:@"grid.png"],[UIImage imageNamed:@"list.png"],nil]];
    [segmentedControl addTarget:self action:@selector(segmentedAction) forControlEvents:UIControlEventValueChanged];
    segmentedControl.frame = CGRectMake(0, 0, 90, 40);
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    segmentedControl.momentary = YES;
    [segmentedControl setTintColor:[UIColor clearColor]];

    UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];    
    self.navigationItem.rightBarButtonItem = segmentBarItem;

I had put it in right side. So, also want to put in middle of navigation bar.

This does not work please let me know if I did anything wrong.

Thanks

  • 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-24T01:49:01+00:00Added an answer on May 24, 2026 at 1:49 am

    You’re almost there, you just need to add the segmented control to a UINavigationItem and add that to your UINavigationBar:

    // This code is used for a custom navigation bar
    
    UINavigationItem* newItem = [[UINavigationItem alloc] initWithTitle:@""];
    [newItem setTitleView:segmentedControl];
    
    // Assuming you already have a navigation bar called "navigationBar"
    [navigationBar setItems:[NSArray arrayWithObject:newItem] animated:NO];
    
    // No memory leaks please...
    [newItem release];
    

    or if you want to use an existing controller

    // This is used for an existing navigation controller
    [navigationController.navigationBar.topItem setTitleView:segmentedControl];
    // or if you want to access through the root view controller of the nav controller
    [rootController.navigationItem setTitleView:segmentedControl];
    

    That should set the center view of your navigation bar to the segmented control.

    Hope I could help!

    EDIT: If you need more help, the Apple documentation of these classes is quite thorough:

    UINavigationItem

    UINavigationBar

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have a UIViewController which has an Add and a Trash button
Is this an heresy to add a UISegmentedControl to a navigation Controller Toolbar? I
I've a custom UITableViewCell which has a UISegmentedControl added as a subview via the
I add asp.net file upload control as follows: <asp:FileUpload ID=filesFileUpload runat=server /> <asp:RegularExpressionValidator ID=RegularExpressionValidator3
I currently have a UISegmentedControl set to add/remove table view cells when its value
I am currently adding a UISegmentedControl to the toolbar in the navigation controller programmatically
I'm trying to either add 3 custom buttons to my navigation controller toolbar on
Does anyone know how to add a scope bar to a UITableView ? The
add({ title: args.node.id, iconCls: 'tabs', items: [{html: '<code class=prettyprint><?php\necho \'Hello World!\';</code>', width: '100%', hieght:
I want add a UIToolbar to the keyboard for my UITextField . Here is

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.