sizeWithFont deprecated ERROR, how to fix?

119 Views Asked by At

I tried using sizeWithAtrributes but it just breaks, not sure what I'm doing wrong this is the error that come up sizeWithFont:minFontSize:actualFont:forWidth:lineBreakMode: is deprecated in iOS7:

if (theRect.size.width > self.bounds.size.width - rightIconNeeds - leftIconNeeds) {
    CGFloat finalSize = realLabel.font.pointSize;
    theRect.size = [realLabel.text sizeWithFont:realLabel.font
                                    minFontSize:realLabel.font.pointSize * realLabel.minimumScaleFactor
                                 actualFontSize:&finalSize
                                       forWidth:self.bounds.size.width - rightIconNeeds - leftIconNeeds
                                  lineBreakMode:realLabel.lineBreakMode];
}
1

There are 1 best solutions below

0
Nicolas Buquet On

I use this instead:

CGRect r = [str boundingRectWithSize:CGSizeMake(sizeLimit.width, CGFLOAT_MAX)
                             options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
                          attributes:@{NSFontAttributeName:realLabel.font}
                             context:nil];
r = CGRectIntegral(r).size;