theAlse
theAlse

Reputation: 5757

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?

Upvotes: 4

Views: 2857

Answers (3)

Qun Li
Qun Li

Reputation: 1316

May be you want to increase the button's focus area, but the button's image still not be changed. I have two ways.

1. the image you can use UIImageView to addSubView // To set imageView's position with freedom. Then override the function:

enter image description here

2. After set button's frame, then set the image's position and size .eg: [button setImageEdgeInsets:UIEdgeInsetsMake(up, left,bottom, right)]; enter image description here

Upvotes: 1

Mostafa Sultan
Mostafa Sultan

Reputation: 2436

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

Upvotes: 7

KKRocks
KKRocks

Reputation: 8322

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.

Upvotes: 2

Related Questions