Author Topic: How to measure a UILabel text's width when using TrueType font?  (Read 1823 times)

Santos

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
How to measure a UILabel text's width when using TrueType font?
« 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,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to measure a UILabel text's width when using TrueType font?
« Reply #1 on: January 20, 2015, 09:44:17 PM »
First call label.UpdateNGUIText(), then NGUIText.CalculatePrintedSize. There is no need to set the bitmapFont yourself.

Santos

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: How to measure a UILabel text's width when using TrueType font?
« Reply #2 on: January 21, 2015, 11:02:38 AM »
Works like a charm.

Thanks,