1

My App is too old. Now, I want to update with latest IOS. My Deployment Target is 6.0 but when I change my Deployment Target 6.0 to 7.1. My app throws too many warnings. and this is one of them :

'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:

The warning occur in this line:

CGSize expectedLength = [str sizeWithFont:str.font constrainedToSize:max lineBreakMode:str.lineBreakMode];  

I will try with this code. but I don't know how to add line break mode. Please check:

CGSize mysize = [str sizeWithAttributes:@{NSFontAttributeName: str.font}];

I already checked in StackOverflow. but I am not satisfied with checked answers because of lineBreakMode.
May be I missed some of good answers. Also tell me the StackOverflow link which will help me.

Thanks in Advance.

Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
  • You've not said what you don't like about the `lineBreakMode`, maybe if you show your existing code, the new code you've tried and what's not working someone might be able to help – Flexicoder Feb 08 '16 at 08:15
  • Ok I will add new code which I tried. – Mihir Oza Feb 08 '16 at 08:18
  • @Flexicoder Please check my updated question. – Mihir Oza Feb 08 '16 at 08:24
  • This answer should help http://stackoverflow.com/a/15399767/285190 – Flexicoder Feb 08 '16 at 11:06
  • yes I know but what about my **lineBreakMode**? – Mihir Oza Feb 08 '16 at 11:24
  • My understanding is that lineBreakMode, is no set using the options parameter, so you will need to change your code to use the new options https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/c/tdef/NSStringDrawingOptions – Flexicoder Feb 08 '16 at 12:03

1 Answers1

1

Thanks all of you. With the help of another questions I solved my Problem at last. Here is my code which I replace with old code :

    CGSize max = CGSizeMake(str.frame.size.width, 500);
    CGRect expected1 = [str boundingRectWithSize:max options:NSStringDrawingUsesLineFragmentOrigin  
    attributes:@{NSFontAttributeName: str.font } context:nil];
    CGSize expected = expected1.size;
    NSLog(@"expected %@",NSStringFromCGSize(expected));
Mihir Oza
  • 2,768
  • 3
  • 35
  • 61