0

How can I produce following code using sizeWithAttributes method:

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

I need to have label width!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
aakpro
  • 1,538
  • 2
  • 19
  • 53

2 Answers2

3

Use like this

CGSize size = [string sizeWithAttributes:
                       @{NSFontAttributeName:
                         [UIFont systemFontOfSize:17.0f]}];
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
0
CGFloat labelWidth = [label.text sizeWithAttributes:[NSDictionary 
                      dictionaryWithObject:label.font forKey:NSFontAttributeName]].width;
Basheer_CAD
  • 4,908
  • 24
  • 36