Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
I've never seen this before.

Trying to Resize my buttons to iPad. Dimensions.
Code:
UIButton *helpButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    helpButton.frame = CGRectMake(95.0*scalerX, 368.0*scalerY, 38.0*scalerX, 35.0*scalerY);
    helpButton.backgroundColor = [UIColor clearColor];
    [helpButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal ];
    UIImage *helpButtonImageNormal = [UIImage imageNamed:@"Help_buttons_Normal.png"];
    UIImage *helpStrechableButtonImageNormal = [helpButtonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [helpButton setBackgroundImage:helpStrechableButtonImageNormal forState:UIControlStateNormal];
    UIImage *helpButtonImagePressed = [UIImage imageNamed:@"Help_buttons_Selected.png"];
    UIImage *helpStrechableButtonImagePressed = [helpButtonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [helpButton setBackgroundImage:helpStrechableButtonImagePressed forState:UIControlStateHighlighted];

[overlayHelpScreen addSubview:helpButton];  

  // ... Etc.

but the image distorts to this:

8284407811_b6213663be_m.jpg


thanks.
Ian
 

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
Caps too big

Figured something about the Size and it being bigger than the frame.
or the Frame + Caps are bigger than <Some internal Whatchamajigg>

Please feel free to fill in details. but

Code:
 UIImage *helpStrechableButtonImageNormal = [helpButtonImageNormal stretchableImageWithLeftCapWidth:0 topCapHeight:0];

Fixed it. If anyone wishes to elaborate It would be Muchly appreciated.
thanks
Ian
 

CodeBreaker

macrumors 6502
Nov 5, 2010
494
1
Sea of Tranquility
Can you post the original image, and the size you want it on the iPad?

Stretchable images are generally used when the image has something special on the edges, and a constant repeating stuff everywhere else.

For example, consider a 100 px X 100 px image with a white fill and a 4 px black stroke (border). In this case, instead of exporting a 100 X 100 image, you can export a 10 X 10 image (a.k.a, texture), such that it contains the 4 px border on all sides and just a 2 px fill in the middle.

When displaying it in a 100 X 100 image view, you would specify the left cap and top cap heights as 4 px. So the returned image will be something like this:

4 px black border on left
92 px white fill (the middle white pixels of the texture are repeated to produce this)
4 px black border on right

4 px black border on top
92 px white fill (the middle white pixels of the texture are repeated to produce this)
4 px black border on the bottom
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Other irrelevant question. Why are you doing this?
Code:
UIButton *helpButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

You are making an autoreleased object, and then hardcode retain in, why didn't you make your project ARC? And just retaining your autoroleased object is quite lame to x)
 

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
Original image

Original image was only 59 X 59.

I'm just too lazy to port to ARC for this project. When I tried it on current
code exploded and I was too close to release.

Memory leaks have been plugged almost 98.7% and just wanted it out there.
Next version or New Game will use ARC..

caps were my problem and removing them the solution. I guess if I had
Some sort of border on the original artwork it would have been fine.
but it didn't so it did.. hahaha !!! the ugly stretching..

Happy holidays
Thanks
Ian
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.