Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make an empty UITextView scrollable like Notes on iOS?

In iOS how do you make a UITextView scrollable and responsive to touch when there's little or no content?

In my app, once text fills up the textview, scrollbars appears and I can scroll around. Less than that though, and since all the content is withen the frame of the UITextView, it's static and doesn't move.

What I want would work like the iPhone Notes application, whether there's one line of text or even when a note is empty, you can scroll the view.

Right now I'm only using a UITextView, and I'm having a hard time understanding whether a UIScrollView is also needed.

I wasn't able to find a question specific to this issue. Thanks!

like image 495
Malcolm Bastien Avatar asked Sep 06 '25 17:09

Malcolm Bastien


1 Answers

For anyone that stumbles upon this page in the future:

I was able to achieve this by simply enabling alwaysBounceVertical, and making sure User interaction and scrolling was enabled.

self.textView.scrollEnabled = YES;
self.textView.userInteractionEnabled = YES;
self.textView.alwaysBounceVertical = YES;

For Swift 3.0:

    textView.alwaysBounceVertical = true
    textView.isUserInteractionEnabled = true
    textView.isScrollEnabled = true
like image 94
serenn Avatar answered Sep 09 '25 16:09

serenn