Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UISegmentcontrol font and selected segment colour? [duplicate]

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];

    }
like image 627
Desmond Avatar asked Dec 08 '11 05:12

Desmond


1 Answers

You may want to check out this: http://idevrecipes.com/2010/12/11/custom-segmented-controls/

like image 145
Jayson Lane Avatar answered Oct 25 '22 05:10

Jayson Lane