Resize UITextView according to the amount of content

0

I'm creating a canvas where I have UITextView that receives content from a Web Service, I'd like to know how do I UITextView resize according to the amount of content I get, without creating a Scroll in the text, only the View has a UIScrollView that according to the size of the UITextView it determines the size of the UIScrollView on the screen, I managed to do but only when I change the content, the problem is that I will not change , because the content comes through a feed. Could someone help me?

-(void)textViewDidChange:(UITextView *)textView{
        CGFloat fixedWidth = textView.frame.size.width;
        CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
        CGRect newFrame = textView.frame;
        newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
        textView.frame = newFrame;
    }
    
asked by anonymous 24.03.2016 / 17:25

1 answer

0

Are you using Autolayout ?

If yes, uncheck Scrolling Enabled in UITextView ...

...removeheightconstraint(ifany)andsettheContentHuggingandContentCompressionsprioritiestohighervaluesthantheothermainviewsubviews

Such changes should solve your problem!

    
30.03.2016 / 20:52