Search code examples
iphoneiosxcodelocalizationuisegmentedcontrol

Localizing text in a segmented controller within a XIB


I have a segment controller in a XIB with three segments, and I'd like to change the text in each segment from within code. I'm not exactly sure how to refer to individual segments from within code. Is this doable?


Solution

  • UISegmentedControl includes this method:

    - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment;
    

    Just create an outlet from your xib onto your @interface and do:

    [self.mySegmentControl setTitle:NSLocalizedString(@"something", nil) forSegmentAtIndex:0];