Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a custom UIButton image does not resize in Interface Builder?

Why does a custom UIButton image not resize with the button?

I set its view mode to Scale to Fill in Interface Builder, but unlike a UIImageView image, it doesn't respect that setting.

Am I looking in the wrong place or is it not possible?

like image 690
willc2 Avatar asked Jun 30 '09 10:06

willc2


People also ask

How do I resize a button image in Swift?

Using storyboard, select the button, then in the size inspect click the dropdown on size just above Content inset. There is a list of sizes to select from, and this will adjust your image size(if you use system image). The default size is already set when you added the button on the storyboard to the View Controller.

What is UIButton in Xcode?

A control that executes your custom code in response to user interactions.

What is button in iOS swift?

It is a control that enables the user to interact with the application. It is used to trigger the events performed by the user. It executes the custom code in response to user interactions. class UIButton : UIControl.


2 Answers

While this may not be quite what you're after - the background image does scale.

like image 60
teabot Avatar answered Sep 23 '22 09:09

teabot


Try this:

[button setImage:image forState:UIControlStateNormal]; button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; 

In Swift:

button.contentVerticalAlignment = .fill button.contentHorizontalAlignment = .fill 
like image 32
Cao Huu Loc Avatar answered Sep 21 '22 09:09

Cao Huu Loc