是否仅使标签宽到需要的宽度? [英] Make label only as wide as it needs to be?

查看:50
本文介绍了是否仅使标签宽到需要的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这样的水平堆栈视图中,我有3个彼此相邻的标签

I have 3 labels next to each other inside a horizontal stack view like this

第一个和最后一个标签将动态地填充一个可变长度的单词,而中间的标签将始终包含单词"with",例如:用Swift编码!"

The first and last label are going to be dynamically filled with a word of variable length, while the middle one is always going to contain the word "with", for example: "Coding with Swift!"

我不希望每个单词之间都有多余的空间,因为如果单词简短的话看起来会很奇怪.有什么方法可以使标签仅宽到适合其文本所需的宽度?这样一来,所有内容看起来都像一个标签(除非我使中间标签的文字较小).

I don't want there to be extra space between each word as it would look strange if the words are short. Is there any way to make the labels only be as wide as they need to be to fit their text? That way it all looks like one label (except I'm making the middle label have smaller text).

推荐答案

在UIView而不是堆栈视图中添加3个标签. 并设置约束,如图所示.

Add 3 labels inside a UIView instead of stack view. And set constraints as shown in image.

这篇关于是否仅使标签宽到需要的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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