0

I would like to resize the label font according to the number of words in the label field. How do i do that? I can use a fixed size and it doesn't look nice. It will be best if it works fine for both iOS5 and iOS6.

Need some guidance. Thanks

EDIT:

NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

    if ( 6 == [[versionCompatibility objectAtIndex:0] intValue] ) { 

        // Put iOS-6 code here
        titleLabel.minimumScaleFactor = 0.5;

    } else { 

        // Put iOS-5 code here
        titleLabel.minimumFontSize = 5;

    }
lakshmen
  • 28,346
  • 66
  • 178
  • 276

1 Answers1

0

You can do as this:

if(yourLabel.text.length <10){
    yourLabel.font=[yourLabel.font fontWithSize:20]
}
else if(yourLabel.text.length <15){
    yourLabel.font=[yourLabel.font fontWithSize:15]
}
else { //>20
    yourLabel.font=[yourLabel.font fontWithSize:10]
}

Alternatively,

Check that your label is set to automatically resize. In IB, it's called "Autoshrink". Programmatically: it is called adjustsFontSizeToFitWidth

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140