replace deprecated sizeWithFont with sizeWithAttributes

2.5k Views Asked by At

How can I produce following code using sizeWithAttributes method:

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

I need to have label width!

2

There are 2 best solutions below

4
Gajendra Rawat On BEST ANSWER

Use like this

CGSize size = [string sizeWithAttributes:
                       @{NSFontAttributeName:
                         [UIFont systemFontOfSize:17.0f]}];
0
Basheer_CAD On
CGFloat labelWidth = [label.text sizeWithAttributes:[NSDictionary 
                      dictionaryWithObject:label.font forKey:NSFontAttributeName]].width;