Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine CCLabelTTF's dimensions

I'm creating a CCLabelTTF without specifying a size. initWithString:fontName:fontSize: sets the dimensions to CGSizeZero so that the size will be determined automatically to fit the specified text.

However, I'd like to find out later what the size ended up being. I'm most interested in the width.

How can I determine the label's actual size?

like image 611
user371320 Avatar asked Jun 12 '12 21:06

user371320


1 Answers

There are two properties you can look at in the texture, which gets updated every time you set a new string or change font-size, etc.

  • yourTTFLabel.texture.contentSizeInPixels

or

  • yourTTFLabel.texture.contentSize (in points)
like image 97
MechEthan Avatar answered Dec 08 '22 16:12

MechEthan