Author Topic: UILabel text change in code makes it offset on the y axis  (Read 7136 times)

theprojectabot

  • Guest
UILabel text change in code makes it offset on the y axis
« on: October 31, 2012, 03:31:55 PM »
I position my UILabel just perfectly within my UI.  Then I change the text of the UILabel by code and it jumps up like 20 pixels... Any idea why this is happening?  I am using a custom packed font, used glyph to create the bmp txt... Seems to work well for static UILabels, but if I modify the text in code it jumps up.  To counteract this I am having to shift the labels before play.. just looks bad. 

Ideas?
Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel text change in code makes it offset on the y axis
« Reply #1 on: October 31, 2012, 07:01:19 PM »
Based on the little info you've provided I can't tell you what you're doing wrong. There is nothing that would cause a label to move after changing its text.

damelin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UILabel text change in code makes it offset on the y axis
« Reply #2 on: October 31, 2012, 10:45:43 PM »
Look at your UILabel's pivot. If it's 'center' or 'bottom', your text position will 'change' and might goes up, if your new text is longer than the previous one... Maybe?

MortenK

  • Guest
Re: UILabel text change in code makes it offset on the y axis
« Reply #3 on: November 04, 2012, 01:59:12 PM »
I have the same problem, how it looks in preview before starting the game: http://screencast.com/t/uN3mb553Meh

How it looks after changing text by code during gameplay: http://screencast.com/t/Aj7pxQeqLxx

Pivot is set to left (but it happens no matter what the pivot setting is).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel text change in code makes it offset on the y axis
« Reply #4 on: November 04, 2012, 04:48:39 PM »
Certainly doesn't happen here. I see you have Free version of NGUI. Maybe that's the problem? What version of Unity?

theprojectabot

  • Guest
Re: UILabel text change in code makes it offset on the y axis
« Reply #5 on: November 07, 2012, 02:11:42 AM »
that was it... the pivot needed to match my anchors pivot.  For example:

My panel is under an UIAnchor that is set to top right.   My label underneath inside the child panel was set to center.  Once set to top right it now doesnt jump down when I modify text programmatically.

ArenMook thanks for the great product! good luck at Unity!