5

I want to display a certain text in two columns like this one:

================
line1  line4  ||
line2  line5  ||
line3  line6  ||
------------  ||
prev  next    ||

================

I do not want the text to have vertical or horizontal scroll just fit inside the area.

I do not know which View or layout to use - as I am new to IOS development-

thanks

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
triplex xx
  • 101
  • 4
  • possible duplicate of [How to create a view which contain image and text as like newspaper has?](http://stackoverflow.com/questions/7888749/how-to-create-a-view-which-contain-image-and-text-as-like-newspaper-has) – jscs Nov 01 '11 at 05:35
  • @JoshCaswell i have read that post but it did not give any help as i mainly need to display the text in two columns layout – triplex xx Nov 01 '11 at 05:58
  • @JoshCaswell and it did not provide any code example – triplex xx Nov 01 '11 at 05:59
  • Try this post [How to split long NSString into pages](http://stackoverflow.com/questions/3812692/how-to-split-long-nsstring-into-pages) – Paul.s Nov 02 '11 at 00:34

4 Answers4

4

If you have some skills in html, you can use UIWebView to show your text in any way that you can implement in mark-up.

Pavel Oganesyan
  • 6,774
  • 4
  • 46
  • 84
  • @Павел Оганесян yes i have some skills in html but i don't know how to make the text fill the left fixed-size column first then begin to fill the right fixed-size column. thanks – triplex xx Nov 01 '11 at 06:05
1

The page http://www.cocoanetics.com/2011/01/befriending-core-text/ explains how to display two colums text by using the CoreText framework and NSAttributedString. I hope it helps you.

Garoal
  • 2,364
  • 2
  • 19
  • 31
0

Displaying text in two columns using UITextview :

//Declare global variables. 

    NSLayoutManager *_layoutManager;
    NSTextStorage *_textStorage;
    UIScrollView *scrollView;

//Create a scrollview and add it on the main view.

 scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 10, screenWidth-20, screenHeight-20)];

        [self.view addSubview:scrollView];

//Get the file url path of .txt file.

 NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"introduction" withExtension:@"txt"];

//Create text storage :
_textStorage = [[NSTextStorage alloc] initWithFileURL:contentURL
                                                  options:nil
                                       documentAttributes:NULL
                                                    error:NULL];

//Create a layout manager and add it to textstorage
 _layoutManager = [[NSLayoutManager alloc] init];
    [_textStorage addLayoutManager:_layoutManager];

//then call the method

 [self layoutTextContainers];

method definition :

   -(void)layoutTextContainers{

        NSUInteger lastRenderedGlyph = 0;
        CGFloat currentXOffset = 0;

        while (lastRenderedGlyph < _layoutManager.numberOfGlyphs) {

         CGRect textViewFrame = CGRectMake(currentXOffset, 10,
                                           CGRectGetWidth(scrollView.bounds) / 2,
                                              CGRectGetHeight(scrollView.bounds) - 20);

            CGSize columnSize = CGSizeMake(CGRectGetWidth(textViewFrame) - 20,
                                           CGRectGetHeight(textViewFrame) - 10);

            NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:columnSize];
            [_layoutManager addTextContainer:textContainer];

            // And a text view to render it
            UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame
                                                    textContainer:textContainer];

            textView.scrollEnabled = NO;
            [introTextScrollView addSubview:textView];

            // Increase the current offset
            currentXOffset += CGRectGetWidth(textViewFrame);

            // And find the index of the glyph we've just rendered
            lastRenderedGlyph = NSMaxRange([_layoutManager glyphRangeForTextContainer:textContainer]);
        }

        // Need to update the scrollView size
        CGSize contentSize = CGSizeMake(currentXOffset, CGRectGetHeight(introTextScrollView.bounds));
        introTextScrollView.contentSize = contentSize;
    }
-1

I think that you can add 2 uitextviews with the same size. In the left one, you can write lines 1, 2 and 3 and on the others 4, 5 and 6

asterix22
  • 53
  • 1
  • 9
  • that is what i was already trying to do but i face a problem. the problem is how to know that the text fill the left UITextView to start filling the other one.how can i know the exact number of lines (or words) to set to the first UITextView – triplex xx Nov 01 '11 at 13:07
  • i have read this topic before asking.it is not useful in my case.as they are two different cases.thanks for your effort – triplex xx Nov 03 '11 at 13:17
  • Sorry I can't help you more, but if I find anything I would help you – asterix22 Nov 07 '11 at 21:15