Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Santos on January 19, 2015, 05:22:04 PM

Title: How to measure a UILabel text's width when using TrueType font?
Post by: Santos on January 19, 2015, 05:22:04 PM
I'm trying to find out the width of a text in the screen so that I can have a sprite that is always aligned to the text when it changes.

After some research I discovered the NGUIText.CalculatePrintedSize(). However, if I got it right, for it to work first I would need to set it's static bitmapFont property. The problem is that the UILabel in question does uses a TrueType font instead of a Bitmap one.

How can I find out the text's width in this case?


Thanks,
Title: Re: How to measure a UILabel text's width when using TrueType font?
Post by: ArenMook on January 20, 2015, 09:44:17 PM
First call label.UpdateNGUIText(), then NGUIText.CalculatePrintedSize. There is no need to set the bitmapFont yourself.
Title: Re: How to measure a UILabel text's width when using TrueType font?
Post by: Santos on January 21, 2015, 11:02:38 AM
Works like a charm.

Thanks,