cocoa touch - iOS sizeToFit not showing text -


i'm creating these labels storyboard view. have autolayout set off , i'm setting numberoflines 0 text displayed if comment out sizetofit. then, of course, text gets cut off when height greater 40.

- (void)viewdidload {  [super viewdidload]; first = @"this text fits in label"; second = @"this large text large label because words normal sized, shows more button correctly @ bottom right"; third = @"doesn't show more button correctly because wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";  firstlbl = [[uilabel alloc]initwithframe:cgrectmake(13, 57, 295, 40)]; secondlbl = [[uilabel alloc]initwithframe:cgrectmake(13, 152, 295, 40)]; thirdlbl = [[uilabel alloc]initwithframe:cgrectmake(13, 225, 295, 40)];  [firstlbl setfont:[uifont fontwithname:@"helveticaneue-light" size:14]]; [secondlbl setfont:[uifont fontwithname:@"helveticaneue-light" size:14]]; [thirdlbl setfont:[uifont fontwithname:@"helveticaneue-light" size:14]];  firstlbl.linebreakmode = nslinebreakbywordwrapping; secondlbl.linebreakmode = nslinebreakbywordwrapping; thirdlbl.linebreakmode = nslinebreakbywordwrapping;  firstlbl.numberoflines = 0; secondlbl.numberoflines = 0; thirdlbl.numberoflines = 0; [firstlbl sizetofit]; [secondlbl sizetofit]; [thirdlbl sizetofit];  [firstlbl settext:first]; [secondlbl settext:second]; [thirdlbl settext:third];  [self.view addsubview:firstlbl]; [self.view addsubview:secondlbl]; [self.view addsubview:thirdlbl];  } 

you're calling sizetofit before set text, it's sizing down cgrectzero. switch calls , it'll work.

sizetofit doesn't mean "automatically adjust size fit content," means "update size right fit content." subsequent updates text won't change frame.

if want former behavior, automatically sizes content, autolayout easiest road take.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -