Solution 1
Your problem can be solved by simply replacing sizeWithFont: constrainedToSize:
with :
boundingRectWithSize:CGSizeMake(newView.frame.size.width, FLT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Interstate" size:fontSize]}
context:nil];
Solution 2
The sizeThatFits
method can be used to address this problem like this:
while (fontSize > minSize && [newView sizeThatFits:(CGSizeMake(newView.frame.size.width, FLT_MAX))].height >= newView.frame.size.height ) {
fontSize -= 1.0;
newView.font = [tv.font fontWithSize:fontSize];
}
I hope one of these solutions solve your problem. Cheers!