SizeWithFont: minFontSize: actualFontSize: forWidth: lineBreakMode: alternative to iOS7

Help me find an alternative for the deprecated method ...

CGSize size = [title sizeWithFont:buttonFont minFontSize:10 actualFontSize:nil forWidth:_view.bounds.size.width lineBreakMode:NSLineBreakByClipping]; 

Can (boundingRectWithSize: options: attributes: context :) do this? Something like that...

  NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:10], NSFontAttributeName, nil]; CGSize size = [title boundingRectWithSize:CGSizeMake(_view.bounds.size.width-kBorder*2, _view.bounds.size.height) options:NSLineBreakByClipping attributes:attributes context:nil].size; 

I'm right? Waiting for your advice :)

+2
source share
1 answer

Take a look at the previous answer I made here using this code:

 - (CGSize)text:(NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(7.0)) { NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, nil]; CGRect frame = [text boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:attributesDictionary context:nil]; return frame.size; } else { return [text sizeWithFont:font constrainedToSize:size]; } } 
+1
source

All Articles