ios - How can I adjust UILabel height to fit the size? -
i know io7 , later , boundingrectwithsize
can work. in order fit ios version. use sizethatfits calculate.following code:
self.detaillabel.text=@"visit bbc news up-to-the-minute news, breaking news, video, audio , feature stories. bbc news provides trusted"; self.detaillabel.linebreakmode = nslinebreakbywordwrapping; cgsize size =[self.detaillabel sizethatfits:cgsizemake(287, maxfloat)]; //287 label's width set in storyboard [self.detaillabel setframe:cgrectmake(self.detaillabel.frame.origin.x, self.detaillabel.frame.origin.y, self.detaillabel.frame.size.width, size.height)]; self.detaillabel.layer.bordercolor=[[uicolor blackcolor] cgcolor]; self.detaillabel.layer.borderwidth=1;
and result is:
the last 2 word "provides trusted" missing!!!!!!
how ever when append word
self.detaillabel.text=@"visit bbc news up-to-the-minute news, breaking news, video, audio , feature stories. bbc news provides trusted world and";
the result :
my storyboard design is:
i guess wrong line break.. when next line text not long enough next line miss..
try code
self.detaillabel.text=@"visit bbc news up-to-the-minute news, breaking news, video, audio , feature stories. bbc news provides trusted"; self.detaillabel.numberoflines=0; self.detaillabel.linebreakmode=nslinebreakbywordwrapping; [self.detaillabel sizetofit];
Comments
Post a Comment