I think I found a marginal case for sizeWithFont: constrainedToSize: where on the retina screen it sometimes (apparently based on word wrap) returns a height 1 line higher than it really is needed, and more importantly than it really draws.
NOTE. The real code that I use is buried inside the standard table height table vector with vertical orientation, so I redid the problem to the simplest example code. (Please pay attention to this when trying to answer something other than my question :-)
This UIView sample fills it with content, measures the text in accordance (wrapped), fills this rectangle, then draws the text.
On a retina device (or simulator), the height returns 1 line too high, but on a device with a pre-grid (or simulator), it returns the correct height.
I would really appreciate any understanding anyone could have, as this is a mistake that I would like to correct!
Many thanks!
Eric
- (void)drawRect:(CGRect)rect { NSString * theString = @"Lorem ipsum dolor sit ameyyet, consectetur adipiscing elit. Etiam vel justo leo. Curabitur porta, elit vel."; UIFont * theFont = [UIFont systemFontOfSize:12]; CGSize theConstraint = CGSizeMake(rect.size.width - 20, rect.size.height - 20); CGSize theResultSize = [theString sizeWithFont:theFont constrainedToSize:theConstraint];
The whole simple project is available here .
Simulator Images:
http://files.droplr.com/files/9979822/aLDJ.Screen%20shot%202011-01-11%20at%2012%3A34%3A34.png http://files.droplr.com/files/9979822/YpCM .Screen% 20shot% 202011-01-11% 20at% 2012% 3A36% 3A47.png
eric
source share