I config a textView in a UIViewController like following: textView configuration

but when controller viewDidAppear I found that UITextView's contentSize = {375, 242} and UITextView can not scroll.

But if i tap the textView, let the textView begin editing (but edit nothing), then i touch the controller's view let textView endEditing, log the textView, this time contentSize = {375, 361} and UITextView can scroll. Is anybody know why? Thanks.


You can add textView something like,

 UITextView *standardTextView = [[UITextView alloc]initWithFrame:CGRectMake(20, 50, self.view.frame.size.width - 40, 120)];
standardTextView.layer.borderWidth = 1.0;
standardTextView.layer.borderColor = [[UIColor lightGrayColor]CGColor];

standardTextView.delegate = self;
standardTextView.font = [UIFont fontWithName:@"Helvetica" size:17.0];

[self.view addSubview:standardTextView];

then when your content(i.e text) will be bigger than textview's height it will enable scroll otherwise it remains disable!!

  • Yes, i know if i create textView using initWithFrame it can scroll, but i want to know why it didn't work using initWithFrame:textContainer. Is there something wrong with my code? – Conan Sep 14 '16 at 6:37

NSTextContainer has a property called heightTracksTextView which may be interfering with your setup here, as the default is false.

I would double check the height of the NSTextContainer after you initialize the UITextView and after you add the UITextView to the view hierarchy.

Check the documentation here: https://developer.apple.com/reference/uikit/nstextcontainer/1444559-heighttrackstextview

If that doesn't help, let me know, I know I've solved this issue before, but I'm not at my computer right now.

Your Answer

