ios - Dynamic height UITableViewCell auto layout -


i have custom uitableviewcell 1 uilabel. uilabel potentially long fit single row, have dynamically set height of uitableviewcell.

i set leading, top, , height(greater or equal) constraints of uilabel. missing constraints?

productdetaildescriptiontableviewcell *cell = (productdetaildescriptiontableviewcell *)[self productdetaildescriptioncellintableview:tableview                                                                                                       indexpath:indexpath];  cgsize cellsize = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize];  return cellsize.height + 1; 

this calculate height code in tableview:heightforrowatindexpath:

i set preferredwith of uilabel.

when run code, height of cell 0, label`s frame is

(0,-21,42,21) 

i wish can help. thank much!!!

may it's logic full you. make sure label line set 0.(label.numberoflines = 0).it's work me.

//count cell size here - it’s depend on content size of label. put requiredheight method in tableviewcell class.     - (cgfloat)requiredheight     {         cgsize labelsize = [label.text sizewithfont: [label font]                                               constrainedtosize: cgsizemake(300.0f, 300.0f)                                                   linebreakmode: nslinebreakbytruncatingtail];          int rowheight = 30.0f + labelsize.height;          if (rowheight < 44) {             if ([uiscreen mainscreen].bounds.size.width == 320) { // iphone4 & iphone5                  return 45.0f;             } else if([uiscreen mainscreen].bounds.size.width == 375){ // iphone6                  return 54.0f;             }else{// iphone6plus                  return 59.0f;             }          }else{              if ([uiscreen mainscreen].bounds.size.width == 320) { // iphone4 & iphone5                return 30.0f + labelsize.height;             } else if([uiscreen mainscreen].bounds.size.width == 375){ // iphone6                 //return 54;                 return 40.0f + labelsize.height;             }else{// iphone6plus                //return 59;                  return 45.0f + labelsize.height;             }         }     }       //call custom cell class here     - (cgfloat) tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {           atableviewcell *cell = (atableviewcell*)[self tableview:self->tableview cellforrowatindexpath:indexpath];          return [cell requiredheight];      } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -