是否可以设置线之间的 UILabel 距离?
是否可以设置 UILabel 的行之间的距离,因为我有一个 UILabel 包含 3 行,并且换行模式是自动换行?
Is it possible to set a UILabel's distance between the line, as i had a UILabel contain 3 lines, and linebreakmode is wordwrap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您指的是“前导”,它指的是类型行之间的间隙 - 您无法在 UILabel 上更改它。 这是从标签本身的正面推断出来的。 有些人尝试创建类别来覆盖标签的 UIFont 的“leading”属性,但它在渲染时实际上不起作用。
如果您确实需要控制文本行之间的垂直间距,那么最好的选择是以编程方式在固定宽度的每行上放置 1 个 UILabel,并自行控制垂直间距。
If you're referring to "leading", which refers to the gap between lines of type - you cannot change this on a UILabel. That is inferred from the front of the label itself. Some people have tried to create categories to override the "leading" property of the UIFont for the label but it doesn't actually work when rendering.
If you really need to control the vertical spacing between lines of text then your best bet is to programmatically drop 1 UILabel per line of fixed width and control the vertical gap yourself.
以下是如何使用界面生成器和以编程方式设置行距。
从 Interface Builder:
以编程方式:
SWift 4
使用标签扩展
现在调用扩展函数
或使用标签实例(只需复制并执行此代码即可查看结果)
Here is how you can set line spacing using interface builder and programatically as well.
From Interface Builder:
Programmatically:
SWift 4
Using label extension
Now call extension function
Or using label instance (Just copy & execute this code to see result)