How to change UISegmentcontrol font and selected segment colour?

Desmond picture Desmond · Dec 8, 2011 · Viewed 11.7k times · Source

Possible Duplicate:
UISegmentedControl selected segment color
UISegmentcontrol appearances causing issues

Hi i will like to change the default UISegmentControl font to a custom font and change the selected segment color to another color instead of a darker color.

thanks

from this

enter image description here

to this

enter image description here

EDIT:Solution called

//change font size, remove shadow, selected text & background color are different from normal state

-(void)defineSegmentControlStyle
    {
        //normal segment
        NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
                                    [UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor, 
                                    [UIColor clearColor], UITextAttributeTextShadowColor,
                                    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
                                    nil];//[NSDictionary dictionaryWithObject:  [UIColor redColor]forKey:UITextAttributeTextColor];
        [infoSegment setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];

        NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
                                          [UIColor whiteColor], UITextAttributeTextColor, 
                                          [UIColor clearColor], UITextAttributeTextShadowColor,
                                          [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
                                          nil] ;//[NSDictionary dictionaryWithObject:  [UIColor redColor]forKey:UITextAttributeTextColor];
        [infoSegment setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];

    }

Answer

Jayson Lane picture Jayson Lane · Dec 8, 2011