So, I spent two days trying to figure out how to add padding around UIButton in Swift 3. I set a custom image (not background image) and trying to increase tappable area with the following code:
backButton.imageEdgeInsets = UIEdgeInsets(top: -44, left: -44, bottom: -44, right: -44)
But it doesn't work! My biggest success is that the button itself becomes bigger with tappable area staying ridiculously small. Please, help.
You can increase the tappable area with content insets. The button frame increases as well, but maintains your content size while creating an invisibly larger tappable area.
By setting the left inset to 0 you can make the image appear all the way to the left, if you're trying to get 'log in' to appear closer to your arrow, but I'm not sure if that's what you're trying to accomplish.
Or programmatically:
button.contentEdgeInsets = UIEdgeInsets(top: 44, left: 0, bottom: 44, right: 44)
You can also add your image and title together in one button, then set the images left inset to 0 and the titles left inset to 20 for example, and create the effect you're looking for. Again, assuming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With