How to add an image to UIButton so that it does not stretch to fill the button?

I have a UIButton and I add an image to it using this code:

[btnCall setImage:[UIImage imageNamed:@"phoneicon"] forState:UIControlStateNormal];

The problem is that this image is stretched to fill the button, and I don’t want it to be stretched at all - I want it to keep its “natural” size and located in the center of the button, even when the button is resized.

My search in this section shows a group of people with the opposite problem: they set the image, and they want it to stretch to fill the button. What am I doing wrong here?

+5
source share
1 answer

, , "UIViewContentModeScaleToFill", "UIViewContentModeCenter"

btnCall.imageView.contentMode = UIViewContentModeCenter;
+9

All Articles