- Home /
New UI Button: Have sprite fill entire button (overflow).
Hi,
I'm looking for the best way to achieve image overflow in the new Unity UI system. I have a button with an image component that should always remain at 160 x 90 px. I'm putting in different sprites, which I don't have control over (end users can set custom images). Instead of stretching or squashing those images to fit my buttons, I would like to scale them up so that they fill the entire button and mask away the overshoot. In other applications this is often called "overflow".
It sounds like this should be built into the UI system already, so am I missing it or do I have to build my own solution by calculating the sizes and using a mask component?
I don't care about positioning the images other than center, as long as they are not stretched and my buttons are completely filled.
Thanks!
Answer by Mischa · Jul 07, 2015 at 08:59 PM
Simply add the image as a child of the button and add a Mask component to the button itself. If you stretch the image with and check the keep aspect ratio checkbox it should work.
Tutorial for the UI Mask is found here: https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-mask
Your answer
Follow this Question
Related Questions
how do i make my button's source image bigger without changing the button hover/clickable area? 0 Answers
Scrollable Achievement Tabs? 1 Answer
UI Image not blocking raycast 3 Answers
I want to make responsive homescreen. how to make responsive homescreen UI like this example ? 0 Answers
Change the button target image alpha 1 Answer