1
votes

I add an image file to to UIButton image property. But my image resized and looks ugly. So if I'll added my image to UIImageView, I can set contentMode property to UIViewContentModeAspectFit and image will look nice. But if I'll do the same for UIButton nothing changed.
My images large than UIButton size. But I don't want to resize them because I use them for iPhone and iPad. So how can I add image to UIButton with UIViewContentModeAspectFit?

2

2 Answers

6
votes

There is UIImageView property of the UIButton

you can access it and can change its mode like this:

UImageView *image = button.imageView;

now you can call the methods

but remember you will set the UIImage using

[button setImage:imag forState:UIControlStateNormal];
1
votes

Are you sure you set the image in the image property and not in the background image property?

If you set an image on the image property if won't be resized on stretched unless the image is larger than the button itself.

If that's the case I'll recommend to use any image editor program to resize the image to a proper size. Doing this to all of your images will also make you app lighter for download.