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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:46:25+00:00 2026-05-30T07:46:25+00:00

I am programmatically adding a UISegmentedControl to a UINavigationController’s toolbar (I am in a

  • 0

I am programmatically adding a UISegmentedControl to a UINavigationController’s toolbar (I am in a UITableViewController). I want the segmented control to look decent, not filling the entire bar. Also, I want it to rotate with the view and resize. This should be pretty easy but I think I’m missing something. I actually got it to work, but this is not clean code so I am hoping someone can tell me which settings/methods to use for a “proper” implementation.

Getter:

- (UISegmentedControl*)stockFilterSegmentedControl {
if (!_stockFilterSegmentedControl) {
    _stockFilterSegmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"All",@"Holdings", nil]];
    [_stockFilterSegmentedControl addTarget:self action:@selector(stockFilterControlPressed:) forControlEvents:UIControlEventValueChanged];
    _stockFilterSegmentedControl.selectedSegmentIndex = 0;
    _stockFilterSegmentedControl.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    CGRect newFrame = _stockFilterSegmentedControl.frame;
    newFrame.size.height = self.navigationController.toolbar.frame.size.height * .8;
    _stockFilterSegmentedControl.frame = newFrame;
}

return _stockFilterSegmentedControl;
}

Where we insert it:

- (NSArray*)navFooterToolbarArray {
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.stockFilterSegmentedControl];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
return [NSArray arrayWithObjects:flexibleSpace, barButtonItem, flexibleSpace, refresh, nil];    
}

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Stocks";
self.toolbarItems = [self navFooterToolbarArray];
}

And to make it work I had to add:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
NSLog(@"Did autorotate.");
CGRect newFrame = self.stockFilterSegmentedControl.frame;
newFrame.size.height = self.navigationController.toolbar.frame.size.height * .8;
self.stockFilterSegmentedControl.frame = newFrame;
}

What’s the right way to do this?

Thanks,

Damien

  • 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-30T07:46:26+00:00Added an answer on May 30, 2026 at 7:46 am

    The answer is actually really simple – you set the segmentedControlStyle on the segmented control to UISegmentedControlStyleBar and it will resize perfectly without any drama. Autoresizing masks work as expected.

    Thanks,

    Damien

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

Sidebar

Related Questions

I am currently adding a UISegmentedControl to the toolbar in the navigation controller programmatically
I'm current creating a UISegmentedControl programmatically in a view controller's viewDidLoad method and adding
When programmatically adding user controls using LoadControl(string path), when, in the user control's page
I have a UITextField which I am adding programmatically. I want to set the
I want to show a confirm dialog in my asp.net/VB.net application. I'm adding programmatically
I'm programmatically adding ToolStripButton items to a context menu. That part is easy. this.tsmiDelete.DropDownItems.Add(The
I'm adding TextViews programmatically in a for-loop and add them to an ArrayList. How
I'm currently adding a div to use as a slider programmatically, but when I
i am programatically adding Webcontrols in to a User Control i am also adding
I have a XAML based ScatterView to which I'm programmatically adding more Scatterviews (

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.