UIButton Padding in Swift 3

So, I spent two days trying to figure out how to add a pad around UIButton in Swift 3. I set up a custom image (not a background image) and tried to increase the display area with the following code:

backButton.imageEdgeInsets = UIEdgeInsets(top: -44, left: -44, bottom: -44, right: -44) 

But that will not work! My biggest success is that the button itself is getting bigger and the service area remains ridiculous. Please, help. enter image description here

+7
ios swift3 uibutton
source share
1 answer

You can enlarge the display area with tabbed content. The button frame is also enlarged, but maintains the size of your content, creating an invisible large area with the ability to delete.

By setting the left insert to 0, you can make the image in full order on the left if you are trying to “enter” to get closer to your arrow, but I'm not sure what you are trying to accomplish.

enter image description here

Or programmatically:

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

You can also add your image and title in one button, and then set the value to 0 in the left image insert and, for example, insert nested headers to 20, and create the effect you are looking for. Again, assuming.

enter image description here

+17
source share

All Articles