Reputation:
Here is the image for that here I had used a separate view as shown in image on the table view cell and I have text that may increase or decrease more than two lines but when I used this code it was setting as expected but it is not having same height of all cells and in storyboard I had set the label properties like lines = 0
and line break = word wrap
tableDetails.rowHeight = UITableViewAutomaticDimension
tableDetails.estimatedRowHeight = 300
When I get only one word in the table view after running the application it was setting in the label perfectly but when I scroll down and up the table view text was arranging as shown in the image
Upvotes: 0
Views: 140
Reputation: 396
If your are using autolayout then do the following steps in you uitableview cell view:
1- For the label which you want to be dynamic according to the text add contraints from all 4 side without adding any height and width contraints.
2- Make number of lines 0 for the label
3-If you are having labels below the label which you want to expand dynamically add contraints from left right and bottom. Don't add contraints from top.
4- In your view controller where you have added the tableview add the following Code:
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 )
{
tbl.rowHeight=UITableViewAutomaticDimension;
tbl.estimatedRowHeight = 80.0;
}
Upvotes: 4
Reputation: 51
You have given Wrong Constraints to your label : Try giving Constraints as [leading with your image and top from view] It works for me. https://i.sstatic.net/9uXAD.png
Upvotes: 1
Reputation: 2652
It's totally dependent on the frame of the label. There may be the following reasons: 1. Check once again for the line break mode of the label it seems characterWrap according to your image. 2. Try to debug with the frame print the frame of label for each label and check for width, is it right that you want?
OR Cross check your constraints too.
Upvotes: 0