Search code examples
objective-ciosuisegmentedcontroltextcolor

How to change text color in UISegmentControl?


Can anyone advise me on how I can change the text color of a UISegment Control?


Solution

  • The Apple Documentation does not specify a method for doing this programatically. The easiest way to do this would be to take a screen shot of each of the segmented control segments without text on them. Then open up photoshop or gimp and add the desired text with whatever coloring you would like. Then tell the slider to you your images like so (Assumes 2 Segments):

    UIImage *segmentOne = [[UIImage imageNamed:@"segmentOne.png"] stretchableImageWithLeftCapWidth:4 topCapHeight:0];
    UIImage *segmentTwo = [[UIImage imageNamed:@"segmentTwo.png"] stretchableImageWithLeftCapWidth:4 topCapHeight:0];
    [_segmentedControl setImage:segmentOne forSegmentAtIndex:0];
    [_segmentedControl setImage:segmentTwo forSegmentAtIndex:1];