Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UIButton bigger than its image

I have created a number of UIButton in my iOS application using the interface builder. Each UIButton also has its own image (no title).

I would like to increase the size of the button without disturbing the image size inside of it (making the touch-area bigger without changing the image size).

Is this possible to do using the interface builder? I have played around with pretty much every option in the button page but have not find anything yet?

like image 860
theAlse Avatar asked Jan 04 '23 09:01

theAlse


2 Answers

found the answer finally here

In Xcode 8 the button content/title/image insets have moved to the Size Inspector tab but we all know that and it's still not working, but there is one more step in the alignment in the below image

illustrating

like image 123
Mostafa Sultan Avatar answered Jan 14 '23 05:01

Mostafa Sultan


You need to set button's height and width as per require (if autolayout enable) . it should be larger than image size .

And now set button's contentEdges :

button.contentEdgeInsets = UIEdgeInsetsMake(15, 20, 10, 10);  //Change x,y,width,height as per your requirement.
like image 34
KKRocks Avatar answered Jan 14 '23 07:01

KKRocks