I am trying to make a cell that will have two UILabels at the same line. Like this:
User Name: blablabla
Where User Name
is the first UILabel and blablabla
is the second UILabel.
I want the first UILabel to be wrap content and the second one to have its content extended until the super view's trailing.
I tried to look for an answer to my question around StackOverflow, but I could not find one. Does someone know how can I achieve that?
I want something just like this:
<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>
or like this
<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>
If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed. If you're editing a UILabel in IB, you can enter multiple lines of text by pressing option + return to get a line break - return alone will finish editing.
A view that displays one or more lines of informational text.
Try to change content compression resistance priority
Look at these snapshots:
Labels with default content compression resistance priority
I changed content compression resistance priority
for label blablabla blablabla
, from 750
to 749
.
Result is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With