How do you add a page break to a uitextview, just like with google docs, Microsoft word, and pdf viewers? I am making an app in which there will be a text editor whose appearance is similar to that of these word processors, so I need to be able to include page breaks in the editable UITextView (I need editable blocks within the uitextview basically). How do I achieve this with SwiftUI or UIKit & Interface Builder?
Asked
Active
Viewed 139 times
1 Answers
0
I believe the short answer is "you don't." A UITextField is not a text editor, and I don't think it supports the concept of pages.

Duncan C
- 128,072
- 22
- 173
- 272
-
But the app "Essayist" is able to do this on iOS devices. Check out the app, and you will see that you will be able to highlight text from all the pages as if it was one uitextbox, even though there is a "page break" between pages. I've also contacted the developers, and they've told me that they've only used UIKit & Swift to make the app. No external libraries were used apparently – Aadi Anand Mar 22 '22 at 00:15
-
Ok, but using UIKit and Foundations is not the same thing a UITextView to display text with page breaks. – Duncan C Mar 22 '22 at 11:22
-
Ok, then what's your suggestion on how I should solve this problem? I have no clue how the Essayist team were able to implement this. – Aadi Anand Mar 22 '22 at 12:46
-
I'd have to do some digging. I suggest asking the developers you've already talked to. They are probably using lower level text objects in Foundation and/or UIKit. – Duncan C Mar 22 '22 at 12:54
-
Check out this thread: https://stackoverflow.com/questions/30634555/how-to-make-uitextview-from-scratch (I'd investigate TextKit.) – Duncan C Mar 22 '22 at 12:59
-
The problem with textkit is that, according to apple, adding more than one nstextcontainer to a uitextview causes the uitextview to become disabled. link: https://developer.apple.com/documentation/uikit/textkit/display_text_with_a_custom_layout quote: "Note that after adding a second text container to the layout manager, the text views become uneditable and unselectable." – Aadi Anand Mar 23 '22 at 10:33
-
You probably need to build your own custom control using TextKit, not add multiple text containers to a `UITextView`. I'm fairly sure that a `UITextView` won't do what you want. – Duncan C Mar 23 '22 at 14:12
-
How do I create my own textview? I can't find any tutorials online in which a custom textview is built from only textkit – Aadi Anand Mar 24 '22 at 02:53