superllanboy
superllanboy

Reputation: 627

splitting an NSString into UITextField pages

I have a number of NSStrings like this:

NSString *eightlabel = @"The process is not permitted to remove material, double-sided upper and lower specification limits, default transmission band for both limits, R-profile, upper limit: arithmetic mean deviation 3,1 μm, evaluation length of five sampling lengths (default), “max-rule”, lower limit: arithmetic mean deviation 0,9 μm, evaluation length of five sampling lengths (default), “16 %-rule” (default.)";

these are added to an array like this:

self.pickerViewArray2 = [NSArray arrayWithObjects:
                             onelabel, twolabel, threelabel, fourlabel, fivelabel, sixlabel, sevenlabel,eightlabel,ninelabel,tenlabel,elevenlabel,twelvelabel,thirteenlabel,fourteenlabel,fifteenlabel,sixteenlabel,seventeenlabel,eightteenlabel,nineteenlabel,twentylabel, nil];

and then later recovered from uipickerview selection and displayed in a uitextview called example:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

    [myPicker selectRow:row inComponent:0 animated:YES];
    [myPicker reloadComponent:0];
    [myPicker selectRow:row inComponent:1 animated:YES];
    [myPicker reloadComponent:1];

    [example setText:[pickerViewArray2 objectAtIndex:row]];

} 

my uitextview is small only 280 x 128 so the text overruns and i need to scroll the textfield, however i would prefer to page the textfield horizontally.

how can i split the nssstring into pages that fit the textview and allow the user to scroll horizontally through the content as required.

the strings are all variable in length and some are small enough to need only one page maximum pages will be probably 2 pages.

any ideas or suggestions will be appreciated.

Upvotes: 2

Views: 657

Answers (2)

rob mayoff
rob mayoff

Reputation: 385700

UITextView doesn't support columns or paged scrolling. You can use a UIPageViewController, or you can do it yourself using Core Text to draw to a custom view inside a UIScrollView.

UIPageViewController is discussed in detail toward the end of the Implementing UIViewController Containment video from WWDC 2011.

I happen to have some sample code that uses Core Text to lay out columns in a UIScrollView. You can find it here: https://github.com/mayoff/core-text-columns/ The ColumnView.m file contains most of the interesting code.

Upvotes: 1

Ell Neal
Ell Neal

Reputation: 6064

UITextView does not support horizontal scrolling. Consider using a UIWebView and HTML string instead.

Upvotes: 0

Related Questions