9

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

    }
Community
  • 1
  • 1
Desmond
  • 5,001
  • 14
  • 56
  • 115

1 Answers1

1

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

Jayson Lane
  • 2,828
  • 1
  • 24
  • 39
  • thanks for the reply, i saw that however i need to set a custom font too... – Desmond Dec 08 '11 at 06:03
  • Maybe this? http://www.iphonedevsdk.com/forum/iphone-sdk-development/5059-change-font-size-text-uisegmentedcontrol.html – Jayson Lane Dec 08 '11 at 06:06
  • Is it possible to change font size of selected segment different from unselected ones in UISegmentedControl? I can change the Color of selected segment but not the font size. – Shreyas Jun 18 '13 at 05:17