How to display text in two columns on iPad

I want to display specific text in two columns like this:

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

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

I don’t want the text to have vertical or horizontal scrolling that just fits into the area.

I don't know which view or layout to use - since I'm new to iOS development -

thank

+5
source share
4 answers

If you have some html skills, you can use UIWebView to display your text in any way that you can implement in the markup.

+4
source

http://www.cocoanetics.com/2011/01/befriending-core-text/ , Framework CoreText NSAttributedString. , .

+1

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];

:

   -(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;
    }
0

, 2 uitextview . 1, 2 3, 4, 5 6

-1

All Articles