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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:10:45+00:00 2026-06-18T08:10:45+00:00

Xcode, Obj-c, iOS 5.2 iOS 6.0 I have a UISegmentedControl which is being inserted

  • 0

Xcode, Obj-c, iOS 5.2 iOS 6.0

I have a UISegmentedControl which is being inserted into the bottom toolbar using something like this:

-(void) makeSegmentedControl {
    self.SegControl = [[UISegmentedControl alloc] initWithItems:@[@"Title1",@"Title2"]];
    self.SegControl.segmentedControlStyle = UISegmentedControlStyleBar;
    [self.SegControl setTarget:self action:@selector(handleSegment) forControlEvents:UIControlEventValueChanged]
    [self.SegControl setSelectedSegmentIndex:0];
 }
 -(void) AddSegmentedControlToToolbar {
     UIBarButtonItem *tmp = [UIBarButtonItem new];
     [tmp setCustomView:self.SegControl];
     [self.navigationController.toolbar setItems@[tmp]];
 }
 -(void) tintSegmentedControl {
     for (int i = 0; i< [self.SegControl.subviews count]; i++) {
          [[self.SegControl.subviews objectAtIndex:i] setTint:[UIcolor greenColor];
      }
      NSArray * sortedViews = [self.SegControl.subviews sortArrayUsingFunction:sortFunction];
      [[sortedViews objectAtIndex:self.SegControl.selectedSegmentIndex] setTintColor:[UIColor lightGreenColor]];
      for (id view in self.SegControl.subviews) {
          [view removeFromSuperView];
      }
      for (id view in sortedViews) {
          [self.SegControl addSubview:view];
      }
 }
 -(void)viewDidLoad {
     [self makeSegmentedControl];
     [self addSegmentedControlToToobar];
     [self tintSegmentedControl];
  } 
  -(void) handleSegment {
      [self tintSegmentedControl];
  }

When I run the similar code in our app it shows a very BLUE UISegmentedController which turns GREEN on clicking. I’ve tried a few things and it seems that the tint on the UISegments just refuses to stick until after the view has finished loading. Any idea what’s happening here?

Edit

So, it turns out I was actually using the iOS 6.0 simulator and there is a restriction in iOS 6 that you can’t tint a UISegmentedController before ViewDidAppear:Animated: has run. I think that this was the problem, because when I make this change:

-(void)viewDidLoad {
     [self makeSegmentedControl];
     [self addSegmentedControlToToobar];
} 
-(void)viewDidAppear {
     [NSTimer timerWithTimeInterval:0 target:self selector:@selector(tintSegmentedControl) userInfo:nil repeats:NO];
}

it works. Not 100% sure what’s going on. Is there an easier way?

  • 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-18T08:10:45+00:00Added an answer on June 18, 2026 at 8:10 am

    So, it turns out there is a restriction in iOS 6 that you can’t tint a UISegmentedController before ViewDidAppear:Animated: has run. To circumvent it I made this code change (as you can see in the edit).

    -(void)viewDidLoad {
         [self makeSegmentedControl];
         [self addSegmentedControlToToobar];
    } 
    -(void)viewDidAppear {
         [NSTimer timerWithTimeInterval:0 target:self selector:@selector(tintSegmentedControl) userInfo:nil repeats:NO];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In XCode 4.2, I find that I can write a statement like this: [obj
I'm using XCode 4.5.2 to create an iOS universal application. I'd like to use
I'm starting from the Apple-spupplied iOS OpenGL game template in Xcode and I have
I've been pretty good at fixing my Xcode Obj-C errors, but this one has
I'm building an app in Obj-C / Xcode and I'm running into some repetitive
I have an ios xcode project, that compile and running fine for simulator but
Hey all. I'm really new at this obj-c/xcode stuff. I'm trying to load the
Beginner's question in Xcode and obj-c. In my project I have a button with
Hi I am working out Xcode and Obj-C and I am getting this warning:
I am building an iOS 5 app with ARC using clang on Xcode 4.2/Lion.

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.