Skip to main content

Posts

Showing posts with the label sizeWithFont

sizeWithFont method is deprecated. Replace with sizeWithAttributes.

Create category that works for both iOS7 and iOS8 or only use sizeWithAttributes. #import "NSString+StringSizeWithFont.h" @implementation NSString (StringSizeWithFont) - ( CGSize ) sizeWithMyFont:( UIFont *)fontToUse {     if ([ self respondsToSelector : @selector (sizeWithAttributes:)])     {         NSDictionary * attribs = @{ NSFontAttributeName :fontToUse } ;         return ([ self sizeWithAttributes :attribs]);     }     return ([ self sizeWithFont :fontToUse]); } @end Category call :      NSString *text= @"Do any additional setup after loading the view, typically from a nib." ;     CGSize fontSize = [text sizeWithMyFont :[ UIFont fontWithName : @"Helvetica"                                             ...