How do I scale a UIButton's imageView?
For the original poster, here is the solution I found:
commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
This will allow your button to scale horizontally. There is a vertical setting as well.
Took me several hours to figure that one out (the naming of the property is very unintuitive) so figured I'd share.
I'd faced similar problem, where I've a background Image (one with border) and an image (flag) for a custom button. I wanted flag to be scaled down and in center. I tried changing imageView's attribute but didn't succeed and was seeing this image --
During my experiments, I tried :
button.imageEdgeInsets = UIEdgeInsetsMake(kTop,kLeft,kBottom,kRight)
I achieved expected result as :
An Addition Way for config in XIB file.You can choose this option if you want text or image is Scale full fill in UIButton.It's will be the same with code.
UIButton *btn = [UIButton new];btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;