-(CGSize) sizeWithFont2:(UIFont *)font
{
if ([self respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)])
{
CGSize result = [self sizeWithAttributes:@{NSFontAttributeName:font}];
return result;
}
return [self sizeWithFont:font];
}
- (CGSize) sizeWithFont2:(UIFont *)font constrainedToSize:(CGSize)size
{
if ([self respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)])
{
CGRect frame = [self boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:@{NSFontAttributeName:font}
context:nil];
return frame.size;
}
else
{
return [self sizeWithFont:font constrainedToSize:size];
}
}
- (CGSize) sizeWithFont2:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode) lineBreakMode
{
return [self sizeWithFont2:font constrainedToSize:size]; //the NSLineBreakMode not used?
}
Notice that the code has 3 problems:
- For
- (CGSize) sizeWithFont2:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode) lineBreakMode
, the parameter lineBreakMode is not used at all. I don't know how to use it in IOS 7. I look around in stackOverflow and the answers there also do not use that parameter. - Also I think sizeWithFont: in IOS 6 must call sizeWithFont:constraintedToSize: but with a default size. But what would be the size?
- Finally I got warning in
[self sizeWithFont:font];
because it's a deprecated function. I want to remove that warning.
Suggestions?