Author Topic: Dynamically changing sliced sprite  (Read 2860 times)

jrhee

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 13
    • View Profile
Dynamically changing sliced sprite
« on: September 04, 2014, 05:24:55 AM »
Hi,

What is the correct way to change the sliced sprite for a button in code while retaining its original dimensions? I tried something like below which seems to work at first, but when I hover out of the sprite and back into it, the size resets.
  1.         void PushIn(UIButton button)    {
  2.                 UIWidget widget = button.GetComponent<UIWidget>();
  3.                 int width = widget.width;
  4.                 int height = widget.height;
  5.                 button.normalSprite = "UI.glass.card.pressed";
  6.                 widget.width = width;
  7.                 widget.height = height;
  8. //              widget.MarkAsChanged();
  9. //              widget.SetDirty();
  10.         }
  11.  
Thanks-

jrhee

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 13
    • View Profile
Re: Dynamically changing sliced sprite
« Reply #1 on: September 04, 2014, 05:35:49 AM »
Disregard, disabling pixel snap on the button did the trick.