質問

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