iosobjective-csizewithfont

sizeWithFont is deprecated in iOS7


With the new iOS7 sizeWithFont:constrainedToSize:lineBreakMode is deprecated and I receive warnings about it in my XCode 5. I have to say that is not affecting the functionality as far as I can tell but I would like to find an alternative to it in order to remove the annoying warnings. Here's my code related to the problem:

CGSize minimumLabelSize = [self.subLabel.text sizeWithFont:self.subLabel.font constrainedToSize:maxSize lineBreakMode:NSLineBreakByClipping];

and:

expectedLabelSize = [self.subLabel.text sizeWithFont:self.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByClipping];

I wasn't able to figure it out by myself an solution and I don't know what to use instead.


Solution

  • If you read either the documentation of sizeWithFont:forWidth:lineBreakMode: or the header file you would have read that you should use boundingRectWithSize:options:attributes:context: instead.