Reputation: 17834
Unless I am reading the docs wrong, it seems like this method sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
is not returning the proper CGSize. Here's a sample code
NSString *someText = @"$";
CGFloat actualFontSize;
CGSize textSize = [someText sizeWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:100.0] minFontSize:1.0 actualFontSize:&actualFontSize forWidth:10.0 lineBreakMode:UILineBreakModeClip];
The height of textSize
returned is what it would be if the font size is 100.0, not what it'd be at the new reduced font size.
If you then take actualFontSize
and do sizeWithFont:forWidth:lineBreakMode:
:
CGSize newTextSize = [someText sizeWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:actualFontSize] forWidth:10.0 lineBreakMode:UILineBreakModeClip];
Now newTextSize
will contain the correct height.
Anyone else encountered this?
Upvotes: 3
Views: 2536
Reputation: 7573
The problem is your width. Because you have set the minimum font to 1.0 pixels and the width only to 10.0 your textSize will automatically adjust to a lower textSize fitting the 10.0 width that you set yourself.
CGSize textSize = [someText
sizeWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:100.0]
minFontSize:1.0 //the troublemaker
actualFontSize:&actualFontSize
forWidth:10.0 //the troublemaker
lineBreakMode:UILineBreakModeClip];
The other one you posted will return the proper size because you didn't set the minimum textFont and you put your width just right.
CGSize newTextSize = [someText
sizeWithFont:[UIFont fontWithName:@"Futura-CondensedMedium"
size:actualFontSize]
forWidth:currencyRect.size.width //probably not 10 pixels wide
lineBreakMode:UILineBreakModeClip];
Upvotes: 1