-2

Can you please help with adopting code to iOS 7? I have code:

size = [string sizeWithFont:font
                   forWidth:constrainedToSize.width
              lineBreakMode:lineBreakMode];

But Xcode says that sizeWithFont:font sizeWithFont:font and lineBreakMode deprecated in iOS 7.

Help me please with update this line of code.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
Anton
  • 45
  • 1
  • 1
  • 5
  • 1
    Always use the official [documentation](https://developer.apple.com/library/iOS/documentation/UIKit/Reference/NSString_UIKit_Additions/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/NSString/sizeWithFont:forWidth:lineBreakMode:), it clearly says what the replacement method is. – A-Live Dec 05 '13 at 12:38
  • 2
    Have a look here: http://stackoverflow.com/questions/18897896/replacement-for-deprecated-sizewithfont-in-ios-7 – BoBro Dec 05 '13 at 12:39

1 Answers1

0

Use sizeWithAttributes: which takes an NSDictionary.

CGSize fontSize = [string sizeWithAttributes: @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:15]}];
Suhit Patil
  • 11,748
  • 3
  • 50
  • 60