views:

96

answers:

1

I am endeavouring to rotate the imageView property of a UIBUtton without scaling it. The image in question is 24x18 - wider than it is tall - but once rotated into place the image is being scaled to keep those dimension - leaving me with a very squished image. How can I prevent this?

Below is my code ..

-(IBAction)rotateButton
{
NSLog( @"Rotating button" );

[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:.5f];
if( CGAffineTransformEqualToTransform( button.imageView.transform, CGAffineTransformIdentity ) )
{
    button.imageView.transform = CGAffineTransformMakeRotation(M_PI/2);
} else {
    button.imageView.transform = CGAffineTransformIdentity;
}
[UIView commitAnimations];
}

This doesn't happen if I apply the transform to the button instead of button.imageView, so I'm guessing it's a property of imageView that I'm not setting right.

Your clues & boos are most welcome

M.

A: 

I've seen the UIImageView property of UIButtons behave very strangely--it seems that some of their properties are read-only, including the UIViewContentMode setting that is what you're talking about here.

The best solution I've found is to mimic the "button containing an image" setup with a separate UIImageView, and an empty custom-styled UIButton sitting on top of it. Gives you a lot more flexibility to manage the image.

Dan Ray