Xcode:如何为标签文本添加边距/填充? [英] Xcode: How to add margin/padding to label text?

查看:18
本文介绍了Xcode:如何为标签文本添加边距/填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文字的标签:

I have a label with text:

但是,我希望它有更多的填充(如果可能的话,边缘要圆一点).但是当我在我的故事板中拉伸标签使其看起来有填充,然后我重新启动模拟器时,它不会向它添加填充.

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.

我该怎么做?顺便说一句,我正在使用自动布局 + 目标 c

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

推荐答案

如果你想走布局约束路线,这可能是适合你的解决方案:

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.

选择标签并单击 Storyboard 文件右下角的约束面板.

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

选择标签后,应用如上所示的布局约束(确保选择红色线",以便实际应用约束).

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

橙色视图是容器视图.标签就在里面.

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

这篇关于Xcode:如何为标签文本添加边距/填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆