i want show uilabel
dynamic height in uitableview
custom cell.i know following code should work.
this written @ cell row @ index
cell.lblcomment.linebreakmode = nslinebreakbywordwrapping; cell.lblcomment.numberoflines = 0; cell.lblcomment.font = [uifont fontwithname:@"helvetica" size:14.0]; nsstring *celltext = @"test test test test test test test test test test test"; uifont *cellfont = cell.lblcomment.font; cgsize constraintsize = cgsizemake(205.0f, maxfloat); cgsize labelsize = [celltext sizewithfont:cellfont constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping]; cgrect newframe = cell.lblcomment.frame; newframe.size.height = labelsize.height; cell.lblcomment.frame = newframe; cell.lblcomment.text = celltext; [cell.lblcomment sizetofit];
this written @ height delegate method.
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { nsstring *celltext = @"test test test test test test test test test test test"; uifont *cellfont = [uifont fontwithname:@"helvetica neue" size:14.0]; cgsize constraintsize = cgsizemake(255.0f, maxfloat); cgsize labelsize = [celltext sizewithfont:cellfont constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping]; return labelsize.height + 70; }
strange returning single line,i tried printing lable frame height correct it's not showing on simulator.
i tried increasing height in xib same code working fine. not sure here what's wrong assigning height label.can 1 please me.
i got resolved simple replacement.may helps others.
cgsize labelsize; if ([celltext respondstoselector:@selector(sizewithattributes:)]) { labelsize = [celltext sizewithattributes:@{nsfontattributename:cellfont}]; }else{ labelsize = [celltext sizewithfont:cellfont constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping]; }
Comments
Post a Comment