Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Set Vertical compression resistance priority to 749 for UITableViewCell

enter image description hereI am working on making a table view cell that has the following constraint relationships.

    -----------------
    |                |
    |  ____________  |
    |  |          |  |
    |  |__________|  |
    |                |
    |  ____________  |
    |  |label.    |  |
    |  |__________|  |
    |                |
    |  ____________  |
    |  |          |  |
    |  |__________|  |
    |                |
    |  ____________  |
    |  |label.    |  |
    |  |__________|  |
    |________________|

The subviews are as follows: (view, label, view, label). I want the cell to dynamically resize with the two labels, for example, if the first label becomes taller, then the cell should become taller accordingly. If both labels become taller or shorter, the cell should resize accordingly. The two views should have a constant width and height.

If I start with a label I'm fine, a label and a view I'm fine, a label and a label, I'm fine, but if I have 2 labels and a view, as soon as I put the last constraint on the final label, auto-layout throws the error in storyboard (I don't have visible issues when running the app).

The problem is that I don't want to change the compression resistance because I don't want either of the labels to scrunch and I don't see why they would given the provided constraints.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Modify last label's bottom constraint to a constant with relation "Greater Than or Equal"

Your code should look like

enter image description here enter image description here

Hope this works

over 4 years ago · Santiago Trujillo Report

0

It seems like you have set the constraints properly, error on storyboards shows for even a tiny change in constraints like 0.5 pixels too. You can remove bottom constraints of last UILabel and reassign so that conflicting constraints can be rearranged. It will fix this problem.

To get the dynamic cell size:

  1. Set the number of lines for both UILabel to 0.

  2. Update relation of height constraints of both UILabel's from = to >=

  3. Apply the following table delegate method in your code

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

Use UIStackView to resolve the problem:

Rather than adding constraints to all the views, you can take all the view's in a stack view and just assign the top, bottom, leading and trailing constraint to stack view and keep table delegate method. I think this will be more appropriate way.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!