Weird Distortion of UIButton

Discussion in 'iOS Programming' started by IDMah, Dec 18, 2012.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    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:

    [​IMG]

    thanks.
    Ian
     
  2. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #2
    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
     
  3. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #3
    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
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    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)
     
  5. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #5
    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
     

Share This Page