Search code examples
iosobjective-ccocoa-touchuisegmentedcontrol

How to change the font size of a single index for UISegmentedControl?


The way to change the font size for a UISegmentedControl would be the following:

UIFont *font = [UIFont systemFontOfSize:13.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont];
[self.segment setTitleTextAttributes:attributes forState:UIControlStateNormal];

How can I change the font size for a single index in a UISegmentedControl? Or even better, if the text doesn't fit in the segment (instead of "Above", it has "Abo...") the font size should be smaller so that it can fit.


Solution

  • Please try with below code

    for (UIView *v in [[[segment subviews] objectAtIndex:0] subviews]) {
        if ([v isKindOfClass:[UILabel class]]) {
            UILabel *label=(UILabel *) v ;
            lable.font=[UIFont systemFontOfSize:13.0f];
        }
    }