IPhone & # 8594; dynamic cell height

I have a UITableView and Cell that I am developing with Interface Builder. I have two tags. The problem is that one of the tags is text, which can be 500 words or 10 words.

I need a dynamic cell height. How can I handle this, because otherwise I have empty space or the cell height is not enough.

Maybe someone has an idea how to do this?

Best wishes.

+4
source share
2 answers

To find out the size of the text, you can use this method:

- (CGFloat)measureTextHeight:(NSString*)text fontName:(NSString*)fontName fontSize:(CGFloat)fontSize constrainedToSize:(CGSize)constrainedToSize { CGSize mTempSize = [text sizeWithFont:[UIFont fontWithName:fontName size:fontSize] constrainedToSize:constrainedToSize lineBreakMode:UILineBreakModeWordWrap]; return mTempSize.height; } 

Then you can set the size cell:

 -(CGFloat)tableView:(UITableVIew*)tableView heightForRowAtIndexPath(NSIndexPath *)indexPath; 
+5
source
 -(CGFloat)tableView:(UITableVIew*) tableView heightForRowAtIndexPath(NSIndexPath *) indexPath { //here u can check the row number and ur labels and return ur custom height. } 
+2
source

Source: https://habr.com/ru/post/1337977/


All Articles