In iOS 7 sizeWithFont: is deprecated. The suggested replacement method is sizeWithAttributes:
But when I change the method from sizeWithFont: to sizeWithAttributes:
I get different Values.
Here my Code:
CGSize temp = [opt.option sizeWithFont:[UIFont fontWithName:fontFamily size:[self randomFontSize]]];
NSLog(@"Old SizeWithFont value %f x %f",temp.height, temp.width);
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:fontFamily size:[self randomFontSize]]};
temp = [opt.option sizeWithAttributes: attributes];
NSLog(@"New SizeWithAttribute has value %f x %f",temp.height, temp.width);
And the output is :
linespacing 16.33, fontsize 16.00
Old SizeWithFont value 18.000000 x 47.000000
New SizeWithAttribute has value 17.875000 x 46.250000
Do I'm doing something wrong ? I
The attributed text method description implies a behavior difference (boldface added by me)...
It also states that integral sizes should be computed with
ceil()(in other words round-up). Doing so makes your experiment work as expected...