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
  • 307,833
  • 40
  • 508
  • 550
aakpro
  • 1,429
  • 1
  • 19
  • 51

2 Answers2

3

Use like this

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