Resize Uitextview according to the amount of content

Asked

Viewed 46 times

0

I’m creating a screen where there’s a UITextView which receives the content of a Web Service, I would like to know how to UITextView resize according to the amount of content obtained, 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 scope of the UIScrollView on the screen, I was able 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;
    }

1 answer

0

You are using Autolayout?

If yes, uncheck the option Scrolling Enabled in the Uitextview...

Desabilitar Scrolling Enabled

... remove height Constraint (if any) and set priorities Content Hugging and Content Compressions for values higher than the other subviews in the main view.

Aumentar prioridades do UITextView

Such changes should solve your problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.