UILabel autoLayout doesn't work fine

I set UIlabel

to UITableViewCell

I want to dynamically increase the height UITableViewCell

, so I add some constraints with UIlabel

, When you type UIViewController

, the label and height are UITableViewCell

wrong, but if I scroll UITableViewCell

outside the screen and scroll back to the screen, then it works correctly, it's weird.

These are my storyboard limitations

enter image description here

UILabel in TableViewCell while entering UIViewController

enter image description here

It should be

enter image description here

I am trying to add some code (override UILabel)

-(void)layoutSubviews{
    self.preferredMaxLayoutWidth = self.frame.size.width;
    [super layoutSubviews];
}

      

and set the crawl priority with 1000

+3


source to share


4 answers


You can link your constraints to the IBOutlet code. So just try with a height constraint that will programmatically change with the height of the UITableViewCell.



0


source


This is because the height of your label is larger than the text content. If you give it a background color, then you can see that. do not attach the bottom of the label to the bottom of the cell, it will stretch the height of the label.

enter image description here

or you can try



[lable sizeToFit];

      

after setting the string value of the label, this may fix the problem.

0


source


Change the priority of the lower spatial constraint to Low. His fight against content ad

0


source


Use these constraints as per your requirement:
title lable: image1


text:
andtextLabel.numberOfLines = 0;



image2

Output

enter image description here
Follow these links Autolayout or Auto- Tuning

0


source







All Articles