views:

652

answers:

2

Hi

I am using a custom image as the background image for my buttons. I have noticed that the edges of the buttons are cut off sometimes. My buttons vary in size but the behavior doesn't seem to be dependent on the button size. I am creating the buttons programatically. The image I am using is pretty large to cover the entire background.

Can someone please let me know what could be the issue?

More info

Setting the content mode to UIViewContentModeScaleToFill still cuts of the images. Also tried resizing the image but doesn't make a difference.

Thanks.

+1  A: 

Did you try setting the button's dimensions to fit exactly the image?

Is the image just cropped or also blurry (cause it's being resized)? Have you toyed around with UIView's contentMode property for the button?

If you did, did you try increasing/decreasing the width or height by a pixel? I sometimes had blurry buttons even though its dimensions were exactly the image's. Adding or removing an extra pixel sometimes helped.

Sam V
Not setting the contentMode, the button is smaller than the image - that is why am setting the image as the button's backgroundImage and not image so it occupies the entire area of the button. Will try resizing the image.
lostInTransit
+1  A: 

I finally resolved this by creating a 3x3 px image with the background color as the button's color and a 1 px border surrounding the image. Then used the UIImage method stretchableImageWithLeftCapWidth:topCapHeight: to create an image with the desired border size of 1 px.

lostInTransit