Question

How can I produce following code using sizeWithAttributes method:

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

I need to have label width!

Was it helpful?

Solution

Use like this

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

OTHER TIPS

CGFloat labelWidth = [label.text sizeWithAttributes:[NSDictionary 
                      dictionaryWithObject:label.font forKey:NSFontAttributeName]].width;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top