0

I'm developing an iOS 4 app using latest SDK and Xcode 4.2.

I've added programmatically a UINavigationController on AppDelegate, and I set it black.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    viewController.title = @"Menu";
    navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    navController.navigationBar.tintColor = [UIColor blackColor];

    self.window.rootViewController = navController;

    [self.window makeKeyAndVisible];
    return YES;
}

On one view controller, I've added a UISegmentedControl:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.


    // Do any additional setup after loading the view from its nib.
    segmentedControl = [[UISegmentedControl alloc] initWithItems:
                                            [NSArray arrayWithObjects:
                                             [NSString stringWithString:@"Past"],
                                             [NSString stringWithString:@"Present"],
                                             [NSString stringWithString:@"Future"],
                                             nil]];

    [segmentedControl addTarget:self action:@selector(segmentedChanged:) forControlEvents:UIControlEventValueChanged];
    segmentedControl.frame = CGRectMake(0, 0, 260, 30);
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    segmentedControl.selectedSegmentIndex = 0;

    self.navigationItem.titleView = segmentedControl;
}

But, when I set one item selected, I can see it because is black.

Is there anyway to set to another color when a item is selected?

VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • You may get help from [This][1] [1]: http://stackoverflow.com/questions/2270526/uisegmentedcontrol-selected-segment-color – mashios Dec 30 '11 at 12:46

1 Answers1

0

Try using the segmentedControlIndexChanged and then detect which one is selected with self.segmentedControl.selectedSegmentIndex and change that segments color.

Kinetic Stack
  • 788
  • 12
  • 33