Author Topic: Scale a Button  (Read 6680 times)

Chamnana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Scale a Button
« on: January 10, 2013, 07:47:05 AM »
Hello,
I have a project where i want to change the label of a button with a script while playing a game, sometimes the text that i'll put in the label is much longer than another (it can be a sentence, just two words, a number... ).
So my question is : how can i scale the label to fit the button (the background of the button have to stay the same for all the labels) ?


Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Scale a Button
« Reply #1 on: January 10, 2013, 08:13:40 AM »
Add an UIStrech on the Background of the Button and set the Style to Horizontal, reference your label as the Widget Container.

If you want some space between the text and the border of the background, add empty char at the left and the right of the Label.Text (Don't know if there is a better solution to do that).
Graphicstream Dev.

Chamnana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Scale a Button
« Reply #2 on: January 10, 2013, 08:19:52 AM »
Thank you :) i'll try that !

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Scale a Button
« Reply #3 on: January 10, 2013, 08:29:28 AM »
Another important thing is to update the BoxCollider on the button. After changing the label, report the scale of the background into the scale of the BoxCollider on the Button.
Graphicstream Dev.

Chamnana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Scale a Button
« Reply #4 on: January 10, 2013, 08:43:51 AM »
Thank you but it's not what i meant. I need the background to still the same, but the label to change its scale... i tried to do the stretch on the label but it doesnt work neither (thanks for the reminder about the collider !) .

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Scale a Button
« Reply #5 on: January 10, 2013, 09:16:49 AM »
Ah ok you want the text to be resized down in the button :)

Graphicstream Dev.

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Scale a Button
« Reply #6 on: January 10, 2013, 09:22:30 AM »
Multiline label may help you there.
Set the Line Width in the UILabel to be the same value as the X value of the Background's scale.

It depends of your needs but this could be ok for you, otherwise you will need to create a custom label management that will auto scale the label depending of its length.
Graphicstream Dev.