Вопрос

How can I produce following code using sizeWithAttributes method:

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

I need to have label width!

Это было полезно?

Решение

Use like this

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

Другие советы

CGFloat labelWidth = [label.text sizeWithAttributes:[NSDictionary 
                      dictionaryWithObject:label.font forKey:NSFontAttributeName]].width;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top