问题
I am experiencing a strange issue related to boundingRectWithSize:options:attributes:context:
This is the code
NSString *text = @"These long strings work";
CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT);
CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16.0]} context:nil];
CGSize size = rect.size;
I have an xcode iOS project which uses this code. When I run the project, the size
is (width=149.8125, height=18.1796875)
I created a new single page application project in xcode and tested the same code there.
size
is (width=172.944031, height=19.0880013)
(which matches the frame size of UILabel created with same title and same font in interface builder)
Apple docs for boundingRectWithSize:options:attributes:context
:
Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics
Is this behaviour due to some display characteristics
that might be different across projects?
来源:https://stackoverflow.com/questions/25562838/weird-behaviour-of-boundingrectwithsizeoptionsattributescontext