ios - How to calculate height of custom UITableViewCell by using UILabel's content -


how can calculate height of custom uitableviewcell using uilabel's content in table view cell?

implement heightforrowatindexpath this:

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {      nsstring *text = [dataarray objectatindex:indexpath.row]; //your data string      cgsize constraint = cgsizemake(yourlabel.frame.size.width, 2000.0f);     cgsize size;      nsstringdrawingcontext *context = [[nsstringdrawingcontext alloc] init];     cgsize boundingbox = [text boundingrectwithsize:constraint                                              options:nsstringdrawinguseslinefragmentorigin                                           attributes:@{nsfontattributename:yourlabel.font}                                             context:context].size;      size = cgsizemake(ceil(boundingbox.width), ceil(boundingbox.height));      return size.height; } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -