Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: How to add margin/padding to label text?

Tags:

xcode

ios

I have a label with text:

enter image description here

However, I want it have more padding (and for the edges to be a little rounded if possible). But when I stretch the label in my storyboard so that it appears to have padding, and then I restart the simulator, it doesn't add padding to it.

How would I do this? BTW, I'm using auto layout + objective c

like image 954
bigpotato Avatar asked Sep 06 '15 23:09

bigpotato


1 Answers

If you want to go the layout constraints route, this is probably the fitting solution for you:

You should use a container view and place the label inside of that. Then add constraints for the label, which will be equivalent to a padding.

enter image description here

Select the label and click the constraints panel at the bottom right in the Storyboard file.

Label's constraints to container view

With the label selected, apply layout constraints like seen above (make sure you select the red "lines" so that the constraints are actually applied).

End result

The orange view is the container view. The label is right inside of that.

like image 108
the_critic Avatar answered Sep 28 '22 03:09

the_critic