Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap Content UILabel in xCode

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>
like image 666
Augusto Carmo Avatar asked Mar 16 '18 10:03

Augusto Carmo


People also ask

How do you wrap text in UILabel?

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.

What is UILabel in Swift?

A view that displays one or more lines of informational text.


1 Answers

Try to change content compression resistance priority

Look at these snapshots:

Labels with default content compression resistance priority

enter image description here

I changed content compression resistance priority for label blablabla blablabla, from 750 to 749.

Result is:

enter image description here

like image 88
Krunal Avatar answered Oct 30 '22 03:10

Krunal