objective c - AutoLayout Scrolling UITextView sizeThatFits not working -


in uiviewcontroller, have non-editable attributed uitextview scrolling enabled, , resize height of scrolling text accommodate screen size widths without having white space. using autolayout , set outlets textview , height constraint. in view controller's viewdidload method use sizethatfits method update textview height, resulting size small.

- (void)viewdidload{     [super viewdidload];     nslog(@"init height: %f, mytextview.frame.size.height);     cgsize sizetofit =     [mytextview sizethatfits: cgsizemake(mytextview.frame.size.width, maxfloat)];     mytextviewheightconstraint.constant = sizetofit.height;     [mytextview updateconstraints];     [mytextview layoutifneeded];     nslog(@"new height: %f", mytextview.frame.size.height); } 

the log indicates height indeed changed default of 4000 2502, 2502 see half of text via scrolling. avoiding nesting text view in scroll view, 1 solution suggests, since discouraged in documentation. missing? in advance.

i found frame of uitextview automatically size content, dynamically setting not necessary. sizethatfits uiview method , doesn't modify size of text content, rather size of window text appears in. code needed scroll text top:

    [mytextview scrollrecttovisible: cgrectmake(0,0,1,1) animated:no]; 

this, autolayout constraint updates shouldn't made in viewdidload, rather in viewdidlayoutsubviews or viewwillappear. best placement explained better - i'm open comments.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -