Mihir Oza February 2016

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

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.

Answers


Mihir Oza February 2016

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));

Post Status

Asked in February 2016
Viewed 2,225 times
Voted 6
Answered 1 times

Search




Leave an answer