Is this an heresy to add a UISegmentedControl to a navigation Controller Toolbar?
I am considering this code:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[NSString stringWithString:NSLocalizedString(@"One", @"")],
[NSString stringWithString:NSLocalizedString(@"Two", @"")],
[NSString stringWithString:NSLocalizedString(@"Three", @"")],
[NSString stringWithString:NSLocalizedString(@"Four", @"")],
nil]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [UIColor blackColor];
[segmentedControl setSelectedSegmentIndex:0];
[segmentedControl addTarget:self action:@selector(changeSegment:)
forControlEvents:UIControlEventValueChanged];
[segmentedControl setFrame:[self.navigationController.toolbar bounds]];
[self.navigationController.toolbar addSubview:segmentedControl];
[segmentedControl release];
I have tried this code and the segments don’t appear to be selected with I touch them.
Is this the correct way of doing that?
thanks.
This is most likely due to your tintColor being black. Change the color and you should see the selected segment reflected.