ios - Setting UITableViewCell height and the cell's text label based on the text height -
i have followed instructions have been able find on stackoverflow fix following none have worked. below code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"doccell"; doccell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[doccell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } // configure cell... cgsize constraintsize = cgsizemake(cell.infolabel.frame.size.width, maxfloat); cgsize labelsize = [_content[[indexpath row] * 2] sizewithfont:[uifont fontwithname:@"helveticaneue-light" size:12.0f] constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping]; cgrect frame = cgrectmake (cell.infolabel.frame.origin.x, cell.infolabel.frame.origin.y, labelsize.width, labelsize.height); [cell.infolabel setframe:frame]; cell.infolabel.linebreakmode = nslinebreakbywordwrapping; cell.infolabel.numberoflines = 10; _font = cell.infolabel.font; cell.infolabel.text = _content[[indexpath row] * 2]; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; return cell; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { cgsize constraintsize = cgsizemake(280.0f, maxfloat); cgsize size = [_content[[indexpath row] * 2] sizewithfont:[uifont fontwithname:@"helveticaneue-light" size:12.0f] constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping]; return size.height + 30.0; }
but when run code height of cells changed appropriately while label size not.
the cell custom cell , have added label via .xib file. tried manually stretching label worked in sense display of text issue not in wrapping of label. have tested cell.infolabel.frame.size.height , height value change height of cell far value concerned not displayed such. doing wrong?
i think problem might of adjusting vertical alignment of text in uilabel instance.
i think should following inside cellforrowatindexpath:
cell.infolabel.text = _content[[indexpath row] * 2]; cell.infolabel.numberoflines = 0; [cell.infolabel sizetofit];
more details can found in following link: vertical alignment of uilabel text
hope helps! :)
Comments
Post a Comment