ios - Incorrect size of a textview frame (self.textview.frame.size.height) -


i want change height of textview depending on content. created method resize view. first time call view controller resize (height = 253) not other times (height = 296).

i tried resizing viewdidappear, viewwillappear , viewdidload. first time viewdidappear , viewdidload called. second , following times methods (viewdidappear, viewwillappear , viewdidload) called. don't know reason , don't know why weird behavior, clue?

-(void) setheight {     nslog(@"set height");     cgrect frame = descriptiontextview.frame;     frame.size.height = descriptiontextview.contentsize.height;     descriptiontextview.frame = frame;     nslog(@"height: %f", descriptiontextview.frame.size.height);      if([[uiscreen mainscreen] bounds].size.height == 568) //iphone 4inch     {         totalheight = 380+frame.size.height;         [self.mainscrollview setcontentsize:cgsizemake(320,totalheight)];     }     else{         totalheight = 250+frame.size.height;         [self.mainscrollview setcontentsize:cgsizemake(320,totalheight)];     }     } 

i use autolayout in project not view since dont know how resize textview inside scrollview (which includes 2 more views labels, images , buttons) based on textview content autolayout. better use autolayout function? perhaps can me constraints...

you changing scroll size according calculation missing change size of text view itself. after setting scroll view content size update size of text view , should fine (contentsize , frame). may like:

[descriptiontextview setcontentsize:cgsizemake(cgrectgetwidth(descriptiontextview.frame),totalheight)]; cgrect frame = descriptiontextview.frame; frame.size.height = totalheight; [descriptiontextview setframe:frame];  

by way: in if-statement can calculate totalheight , set afterwards.

additionally not need line:

frame.size.height = descriptiontextview.contentsize.height; 

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? -