I want to add an image to a UIButton, and also want to scale my image to fit with the UIButton (make image smaller). Please show me how to do it.
This is what I have tried, but it does't work:
- Adding image to button and using
setContentMode
:
[self.itemImageButton setImage:stretchImage forState:UIControlStateNormal];
[self.itemImageButton setContentMode:UIViewContentModeScaleAspectFit];
- Making a "stretch image":
UIImage *stretchImage = [updatedItem.thumbnail stretchableImageWithLeftCapWidth:0 topCapHeight:0];
None of the answers here really worked for me, I solved the problem with the following code:
You can do this in the Interface Builder as well.
I have a method that does it for me. The method takes
UIButton
and makes the image aspect fit.If you simply want to reduce your button image:
For Xamarin.iOS (C#):