ios - dynamic height uilabel -
i trying change uilabel height dynamically text width changes, problem arises when try use line "white wallington hall". calculates width in 2 lines in uilabel, when shows in 2 lines this:
"white wallington h..." sample code:
uilabel* lbl_property = [[uilabel alloc]init]; [lbl_property setfont:[uifont fontwithname:@"arial" size:10]]; [lbl_property setnumberoflines:0]; [lbl_property settext:[arr_subdetail objectatindex:x]]; uifont* font = [uifont fontwithname:@"arial" size:10]; cgsize stringsize = [lbl_property.text sizewithfont:font]; cgfloat width = stringsize.width; [lbl_property setframe:cgrectmake(lbl_property.frame.origin.x, lbl_property.frame.origin.y, lbl_property.frame.size.width,5+lbl_property.frame.size.height*(ceilf(width/110)))]; actually after "white" there space , "wallington" isn't in line goes on new line, not showing complete text
how show right?
try it....
//calculate expected size based on font , linebreak mode of label cgsize maximumlabelsize = cgsizemake(296,9999); cgsize expectedlabelsize = [yourstring sizewithfont:yourlabel.font constrainedtosize:maximumlabelsize linebreakmode:yourlabel.linebreakmode]; //adjust label the new height. cgrect newframe = yourlabel.frame; newframe.size.height = expectedlabelsize.height; yourlabel.frame = newframe;
Comments
Post a Comment