在 xCode 中包装内容 UILabel
Wrap Content UILabel in xCode
我正在尝试制作一个在同一行有两个 UILabel 的单元格。
像这样:
User Name: blablabla
其中 User Name
是第一个 UILabel,blablabla
是第二个 UILabel。
我希望第一个 UILabel 包装内容,第二个 UILabel 将其内容扩展到超级视图的尾部。
我试图寻找关于 Whosebug 的问题的答案,但找不到。有人知道我该怎么做吗?
我想要这样的东西:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/first_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"/>
<TextView
android:id="@+id/second_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bla bla bla"/>
</LinearLayout>
或者像这样
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/first_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/second_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bla bla bla"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/first_label"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
您应该尝试以下解决方案。
第一个标签。
- 添加顶部、左侧、底部、宽度约束。
- 现在将行数设置为 0,将
Autoshrink
设置为最小字体大小,如下所示。您应该设置所需的最小字体大小。
第二个标签
- 添加上、左、下、右。
- 现在将行数设置为 0,将
Autoshrink
设置为最小字体大小,如下所示。您应该设置所需的最小字体大小。
这些更改将使第一个标签的字体自动缩小到您的最小字体大小。并且还会制作第二个标签来扩展内容。
- 您可以通过以下方式做到这一点:
yourLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
尝试更改内容压缩阻力优先级
看看这些快照:
默认标签 content compression resistance priority
我将标签 blablabla blablabla
的 content compression resistance priority
从 750
更改为 749
。
结果是:
我正在尝试制作一个在同一行有两个 UILabel 的单元格。 像这样:
User Name: blablabla
其中 User Name
是第一个 UILabel,blablabla
是第二个 UILabel。
我希望第一个 UILabel 包装内容,第二个 UILabel 将其内容扩展到超级视图的尾部。
我试图寻找关于 Whosebug 的问题的答案,但找不到。有人知道我该怎么做吗?
我想要这样的东西:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/first_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"/>
<TextView
android:id="@+id/second_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bla bla bla"/>
</LinearLayout>
或者像这样
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/first_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/second_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bla bla bla"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/first_label"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
您应该尝试以下解决方案。
第一个标签。
- 添加顶部、左侧、底部、宽度约束。
- 现在将行数设置为 0,将
Autoshrink
设置为最小字体大小,如下所示。您应该设置所需的最小字体大小。
第二个标签
- 添加上、左、下、右。
- 现在将行数设置为 0,将
Autoshrink
设置为最小字体大小,如下所示。您应该设置所需的最小字体大小。
这些更改将使第一个标签的字体自动缩小到您的最小字体大小。并且还会制作第二个标签来扩展内容。
- 您可以通过以下方式做到这一点: yourLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
尝试更改内容压缩阻力优先级
看看这些快照:
默认标签 content compression resistance priority
我将标签 blablabla blablabla
的 content compression resistance priority
从 750
更改为 749
。
结果是: