x


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?

more ▼

asked May 31 '12 at 08:11 AM

blitzen gravatar image

blitzen
180 21 31 34

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jun 08 '12 at 01:05 AM

blitzen gravatar image

blitzen
180 21 31 34

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 31 '12 at 08:31 AM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

Thanks but the issue is not the difference in screen resolution. I have this at the beginning of OnGUI, telling it to behave as if the screen is 1024x768 in all cases:

GUI.matrix=Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3((float)1.0*Screen.width/1024,(float)1.0*Screen.height/768,1.0f));

The problem is that, even when hard-coding the width to a certain number of pixels which it should display it as regardless of screen resolution, it always cuts it down to 50, proportionately less.

May 31 '12 at 08:39 AM blitzen
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x256
x35
x2

asked: May 31 '12 at 08:11 AM

Seen: 412 times

Last Updated: Jun 08 '12 at 01:05 AM