views:

41

answers:

2

Hi,

I don't know if this is possible, but I guess it is. I have a tableview with custom cells. These cells have a UIImageView as background. But because the size of the cell is relative I would like the image view to adapt its size. This is now problem, I can define that in the Interface Builder. But I don't want the corners of my image view to be scaled. Can I somehow assign a grid to the image view telling what now to resize, but only the "center" of that grid should be resized.

To make it a bit more clear, here is an example of what I mean: http://dl.dropbox.com/u/3077127/example_grid.png

Best regards,
Paul Peelen

+1  A: 

Look into UIImage stretchableImageWithLeftCapWidth:topCapHeight: for the next best thing. As long as you set up the image so the center is centered this will work. At runtime you will have to swap out the static image with a stretchable image.

drawnonward
+1  A: 

It is definitely possible. What you want is called "capping". The documentation of UIImage has what you need. The function that you would want is:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth 
                                 topCapHeight:(NSInteger)topCapHeight

You would call it on an instantiated image for your background and assign the result as your UITableViewCell background.

cool_me5000
Great! Thanks alot. Didn't know about that... works perfect! Thanks!
Paul Peelen