user6724161
user6724161

Reputation: 205

Add padding to sides of text in a button

Using Xcode's storyboard, how can I add padding to the left and right of a UIButton's text? I can't for the life of me figure out how to do this.

Here is my button:

enter image description here

I want the button to "hug" the text and then give padding of 32px on the left and right sides of the button.

But when I try to add a Title Inset, it just squeezes the text to a point where it's almost not showing:

enter image description here

So how do I adjust the button's padding properly?

Upvotes: 0

Views: 1892

Answers (1)

Anand
Anand

Reputation: 1946

Ensure following things are done for the Button in storyboard.

  1. Update Content insets value for Left and Right as 32px in Size Inspector in storyboard.
  2. Also, ensure Content Compression Resistance priority - Horizontal value is high (751) for safer side.
  3. Remove if you have any width constraint for Button, if possible.
  4. Do not update Title insets. It will not work as you expected.

enter image description here

I have tested this. It's working for me.

Upvotes: 4

Related Questions