Search code examples
iosswiftuitableviewuilabelios9

Setting the height of UIlabel


I have a label that is in a custom uitableview cell. I am using auto layout to position the label. My question is how can one set the height of the label to zero when it does not have any text. Or how to to make the label height 0. The project supports ios 8 so using stackview is out of the question. The label is also expansive i can't set a constant height constraint.My layout is given below .enter image description here


Solution

  • You can set label's height constraint >= 0. Label will update it's size to the content, and if text is missing height will be 0.

    enter image description here