Search code examples
iphoneobjective-cuiimageuibuttonstretching

Stretchable Images


In reference to: iPhone stretchableImageWithLeftCapWidth only makes "D"s

I have an image of a button of size 13x30. I want to stretch the image to fill the button which will be of size 45x30.

Here is the code I am using:

UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:16.0f topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
etc....

The image I get is quite off. I am getting the image in its real size, with some sort of a lighter shadow behind it as shown in the image button.

Why is this happening? I don't understand at all. I have the stretchable logic correct and I've followed what everyone is saying in tutorials/posts.

If I get some assistance I would greatly appreciate it.


Solution

  • I think your left cap width is wrong? If your first image is only 13 pixels wide, how can the left cap be 16?

    The left cap is the width on the original image that stays unstretched