I have a UIButton without text and there are 2 images that I would like to use (one for the normal state and the other for the selected state). Images are smaller than a button.
How to ensure that none of the images scale when drawing a button? Setting imageView properties only scales correctly for the normal state, but not for the selected one.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:imageNormal forState:UIControlStateNormal];
[button setImage:imageSelected forState:UIControlStateSelected];
button.imageView.contentScaleFactor = 1.0;
button.imageView.contentMode = UIViewContentModeCenter;
source
share