Question

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.

Was it helpful?

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

OTHER TIPS

To follow up on Paul's answer,

You want to make sure that you leave some space for stretching, so zoom in using Photoshop or something similar and decide what left pixels are absolutely required.

See this: http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/

LeftCapWidth should be 6.5;

UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:6.5 topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top