Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda