0

I have a long string which I would like to present, splitted, in several text views using scroll view and PageControl.

Example:

enter image description here

Does anyone know of such a control?

If I'm making the textview with fixed size how can I calculate how much text can fit and splits the string to chunks?

bneely
  • 9,083
  • 4
  • 38
  • 46
ibm123
  • 1,214
  • 2
  • 15
  • 39

3 Answers3

0

You can go two ways in iOS7, each with their pros and cons.

You can go the TextKit way, define multiple text containers (each text area on each page), and use a single layout manager to draw your across the views. The pros of this is that it gives you a lot of control and versatility. The cons, as you have probably figured out, is it is difficult to implement for a small need such as this.

Another way is UIWebView pagination. What this does is create exactly what you need with three lines of code:

_webView.paginationMode = UIWebPaginationModeLeftToRight;
_webView.paginationBreakingMode = UIWebPaginationBreakingModePage;
_webView.gapBetweenPages = 5;

The cons of this is that you have a webview, which is somewhat harder to manage (you load an HTML instead of text).

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
0

If you want to use an NSAttributedString have a look at my answer at iOS UITableView with dynamic text and images rendered together (NSAttributedString + images).

If you just want to use an NSString with one font size you can split your text, by finding out it's size: See Mark Ramotowski's answer here With what should I replace the deprecated sizeWithFont: method?

The docs: https://developer.apple.com/library/ios/documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/boundingRectWithSize:options:attributes:context:

I don't know, if someone wrote a drop in control without custom coding, as you asked for.

Community
  • 1
  • 1
0

Ok, Here is my solution : https://github.com/rorlich/LongTextView

i'm guessing i will need to improve it in the future but it's a good start for now

ibm123
  • 1,214
  • 2
  • 15
  • 39