Manipulate ui canvas button hitbox
This should be simple but can't find it anywhere. I made a UI button and made the source image my own image. I set it to native size and it looks good but..
there seems to be some buffer in between my image and the border that I can't get rid of. I would want the border to hug the edges, or else the user can press the button without touching it. Any ideas?
Answer by united4life · Nov 19, 2015 at 05:20 AM
Hi,
Make sure your button image is not like this.
In the canvas it will look like this.
So make sure your button image size is cropped till the border of the image. There should not be any transparency.
Answer by ian_sorbello · Nov 19, 2015 at 04:40 AM
Working with the UI can be fun AND frustrating :) It will take practice.
But anyway, here is a way to achieve this:
In the RectTransform, choose the Anchor Preset for Stretch X&Y (it's the icon in the lower right corner when you open the Anchor Preset flyout (also the Anchor Preset is the button that has "stretch" and "stretch" next to it
Then (and this is important) - edit LEFT, TOP, RIGHT and BOTTOM values, make them all 0 (this will fill out the image to the full size)
Thanks for response, but this isn't what I want. I would like the border of the button to actually touch its image, with no empty space between. I tried what you said and it just makes the image take the size of the whole screen (with the space still present).
O$$anonymous$$ - You may need to show more detail on the hierarchy and the values set. Other ways to constrain an image is to make the image a child object of the button.
So you have a clear size and position for the button. $$anonymous$$ake a new sub object and add the Image component there. Then do as above and it will fill to the size of it's parent (not the whole screen).
Ok, now it works and fills up to size of the button. But space is still there and its my fault because of a faulty asset I thought i had cropped. Still, +1 for showing me the strech xy.
Your answer
Follow this Question
Related Questions
Problem with creating button via script. 1 Answer
How can I change the UI button color when clicked 1 Answer
Scaling an image sent to UI Image 0 Answers
Share button AR 0 Answers