I have a UIButton, and I'm adding an image to it using this code:
[btnCall setImage:[UIImage imageNamed:@"phoneicon"] forState:UIControlStateNormal];
The problem is that this image is being stretched to fill the button, and I don't want it to be stretched at all - I want it to retain its "natural" size and be positioned in the center of the button, even when the button is resized.
My searching on this topic shows a bunch of people with the opposite problem: they're setting the image and they want it to be stretched to fill the button. What am I doing wrong here?
I think this is because the default content mode is set to 'UIViewContentModeScaleToFill' so you need to set it to 'UIViewContentModeCenter'
btnCall.imageView.contentMode = UIViewContentModeCenter;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With