How to adjust an UIButton's imageSize?

adit picture adit · May 14, 2012 · Viewed 157.5k times · Source

How can I adjust the image size of the UIButton? I am setting the image like this:

[myLikesButton setImage:[UIImage imageNamed:@"icon-heart.png"] forState:UIControlStateNormal];

However this fills up the image to the full button, how do I make the image smaller?

Answer

Tim C picture Tim C · May 14, 2012

If I understand correctly what you're trying to do, you need to play with the buttons image edge inset. Something like:

myLikesButton.imageEdgeInsets = UIEdgeInsets(top, left, bottom, right)