Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl and localized strings

I have a UISegmentedControl with 3 segments. The English strings fit perfectly, but Spanish strings are slightly longer and don't.

enter image description here

enter image description here

What is the correct procedure to manipulate font size dynamically for the string to fit the size of the segment? Is there something similar to the minimumFontScale property for UILabel?

like image 597
Andrew Davis Avatar asked Aug 22 '26 00:08

Andrew Davis


1 Answers

Try This one You didn't need to set any min font size. It will change font size automatically to show title if needed.

NSArray *itemArray = [NSArray arrayWithObjects: @"Title1 testing font size", @"Title2", @"Titl3",nil];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
    segmentedControl.frame = YOUR_FRAME;
    [segmentedControl addTarget:self action:@selector(segmentControlClicked:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentedControl];
    for (id segment in [segmentedControl subviews])
    {
        for (id label in [segment subviews])
        {
            if ([label isKindOfClass:[UILabel class]])
                [label setAdjustsFontSizeToFitWidth:YES];

        }           
    }
like image 161
Surjeet Singh Avatar answered Aug 24 '26 13:08

Surjeet Singh