Button Width Squeezed on the iPad

I have several GUI button images that look fine on Windows, but on the Mac are squeezed down to at most 50 pixels wide no matter what I do.

The buttons are all PNGs created with GIMP and a little transparency around the edges, and most of them display fine except for this one particular set of 384x128 images that I’m trying to display as 128x50:

When played in the Mac editor (and any builds created by it), it ends up being scrunched width-wise down to 50 pixels:

The code is essentially:

GUI.Button(new Rect(84,buttonHeight,128,50),buttonImg){ //bla }

So far I have tried:

  • extending the width of the Rect that the button is drawn with. No change.
  • setting the Fixed Width of the button's GUIStyle. It still caps it to 50 pixels wide even when you slide it above 50, no matter how high.
  • Resizing the actual images to 512x512, 512x256, and 512x128. While their height proportions may change, they still get displayed no wider than 50 pixels.
  • Replacing the image of one of the other buttons elsewhere on the screen that used to display fine with one of these. Its width is still squeezed in that other button's location.

It thus seems to be independent of my code that’s drawing it, and even overriding the GUIStyle. So far I’m not seeing a difference between the images it does it to and the rest that are displayed fine, so it’s pretty whacked. Has anyone encountered this?

The reason is that you have set values for the button sizes. Instead use a dynamic size.

private var scnH:float;//Screen.height
private var scnW:float;//Screen.width

function OnGUI()
{
    GUI.Button(new Rect(scnW/20,scnH/10,scnW/10,scnH/5),buttonImg) 
}

You will have to play with the sizes, but you get the idea. This way you will have the same relative size no matter what the screen size is.

The problem seems to be limited to using an image as the GUIContent argument of GUI.Button, the workaround that ended up with acceptable results was just to make a totally new style for each button (a dozen in my case), and use the image as the “Normal” background of that style.