iosobjective-csizewithfont

replace deprecated sizeWithFont with sizeWithAttributes


How can I produce following code using sizeWithAttributes method:

CGFloat labelWidth = [label.text sizeWithFont:label.font].width;

I need to have label width!


Solution

  • Use like this

    CGSize size = [string sizeWithAttributes:
                           @{NSFontAttributeName:
                             [UIFont systemFontOfSize:17.0f]}];