How to get rid of the padding between UIButton image and the borders of the UIButton?

293 Views Asked by At

I would like to get rid of the spacing between the top of the UIButton image and the top border of the UIButton as well as the bottom of the UIButton image and the bottom border of the UIButton (refer to attached image).

I tried to use the below code however with no avail:

newFileButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

        newFileButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

        newFileButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

Any suggestions are much appreciated.

Regards, Shadi.

enter image description here

1

There are 1 best solutions below

0
jake On

The insets are at zero by default. To get rid of space on the inside, add negative insets.

newFileButton.imageEdgeInsets = UIEdgeInsets(top: -4, left: 0, bottom: -4, right: 0)