Possible Duplicate:
create UIImageView with portion of image file
I have setup a series of buttons of around 30px x 30px. I have an image of size 300px x 300px.
When I set the image as either the image or the background image the image is automatically resized to fit into the button. What I would actually like it to do is to display a 30 x 30 section of the image.
I have tried several methods for doing this however they appear to be fruitless. I have tried over riding -(void)layoutSubviews but this caused the image to be bigger than the button itself and caused other odd behaviours.
I have also tried modifying the image view property but again this also did not work.
Lastly I have tried using imageEdgeInsets but again this had similar behaviour of over riding layoutSubviews.
I would like to do this as I have a numerous buttons that will make up the full picture but these will be moving. An alternative way would be to split the image up in a paint style package but in the long run this will cause extra work and would prefer to do this programatically. Any guidance on how to proceed would be appreciated.
After posting the question I investigated further and came across the following.
Some of the aspects of this are very similar to the question located at create UIImageView with portion of image file
once this is done subImage can simply be added as the image for the uibutton such as:-