iOS - let UILabel stretch to downside when there are multiple lines -
i using setnumberoflines
, sizetofit
resize label in tableview cells dynamically. when there more 2 lines, label stretch upside, want make stretch down.
let's have label1
, label2
. y
position same before setting label.text
:
label1 label2 --------- --------- | | | | --------- ---------
label1 has 1 line while label2 has 2 lines after setting label.text
separately. looks now:
label1 label2 --------- --------- | line1 | | line1 | | line2 | --------- ---------
however, want is:
label1 label2 --------- --------- | line1 | | line1 | --------- | line2 | ---------
i believe there simple way achieve goal, can't find googling keyword can think up.
my code:
mylabel.text = value; [mylabel setnumberoflines:0]; [mylabel sizetofit];
try this:
nsstring *text1 = @"your text label2"; cgsize constraint1 = cgsizemake(125, 2000); //width of label.... cgsize size1 = [text1 sizewithfont:[uifont fontwithname:@"arialmt" size:12.0] constrainedtosize:constraint1 linebreakmode:uilinebreakmodewordwrap]; //font of label cell.mylabel.frame = cgrectmake(posx,posy,125,size1.height); //posy same label1 cell.mylabel.linebreakmode = uilinebreakmodewordwrap; cell.mylabel.numberoflines = 0; cell.mylabel.text = text1;
Comments
Post a Comment