I am looking for a way of finding the correct font size in order to draw text onto a map at the correct width (which changes as the user zooms in and out of the map). I used to use the following code:
+(float) calulateHeightFromMaxWidth:(NSString*)text withMaxWidth:(float)maxWidth withMaxFontSize:(float)maxFontSize{
CGFloat fontSize;
[text sizeWithFont:[UIFont systemFontOfSize:maxFontSize] minFontSize:1 actualFontSize:&fontSize forWidth:maxWidth lineBreakMode:NSLineBreakByTruncatingTail];
return fontSize;
}
This method always returned the correct answer, however sizeWithFont is depicted in iOS 7 and I cannot find a replacement that will return the font size after given it a width. I have found many posts on this site that will give you the width after you have specified a size but I cannot find the opposite (sizeWithAttributes:). I am trying to avoid a solution which involves looping through different font sizes till I find one that fits, as this method could be called 100's maybe 1000's times a draw.