Changing Button Image

  1. 5 months ago

    ingurgite

    Oct 22 User since 2018

    Hi,

    I would like to programmatically change the image of a button when it is pressed. For an image, I can change its value through var.image = image.

    For a button, it seems that there is a notion of state. I've tried all the types of states and could not succeed. Also, it seems that there is no method to retrieve the current state of a button?

    Thanks.

  2. andrea

    Oct 23 Administrator User since 2016

    Hi @ingurgite,
    you can programmatically change the image of a button for a specific state, for example:
    ```
    Button1.setImageForState(image1, ControlState.Normal)
    Button1.setImageForState(image2, ControlState.Highlighted)
    ```

    In this way, the `image1` is presented when the button is in the normal state and the `image2` is presented when the button is pressed.

  3. ingurgite

    Oct 26 User since 2018

    Thanks @andrea. I had tried that but it seems I had made a mistake.

    Thanks a lot.

or Sign Up to reply!