Truncate text and get text that isn't shown in the viewable frame of label ! (Paging of text) - iphone

I have a long text containing line breaks and paragraph breaks; and I want to be able to create pages of the text.
The problem that I am facing is that I am unable to separate out the text that is visible on the page; from the text that goes beyond bounds of the page.
I was able to get the label size that can display all the text via using sizeWithFont:
CGSize expectedLabelSize = [string sizeWithFont:_lbl.font
constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];
Now, I wants to be able to separate out the visible and non visible text and create pages on the basis of it.
Any kind of help will be very much appreciated !

Check out this question here:
How to split long NSString into pages

Related

UILabel does not wrap (if I change default font size)

I am working on a simple storyboard prototype. My TableViewController uses Dynamic Prototype as Content.
I have a cell with 4 label of which two will be set in code (the label text). The height of the cell will be calculated in code too. The Line Breaks are set to Word Wrap and everything's working fine with the default values (System 17.0):
see here:
..but if I change the Font Size of the "Fantasy Street..." label it will not break any more instead it just will be cut off!
see here: with System Font 16
Lines are set to 0
Word Wrap is still active
.. I also tried to do it manually in code but no change.
Does anyone have an explanation for that?
****edited:** when I add
myLabel.frame = CGRectMake(t.origin.x, t.origin.y, t.size.width, t.size.height *2);
to the cellForRowAtIndexPath I still see the cut off label. But if I then scroll the table view so the label is outside the viewable area shortly it will be displayed with the complete text when it is visible again.
By the way, I am working with viewTags, so I don't have a dedicated Cell Class e.g. UILabel *myLabel = (UILabel *)[cell viewWithTag:2];
You should check UILabel width; the width should be less than that of the value. Then like this:
(void) viewWillLayoutSubviews {
_landPhoneTips.preferredMaxLayoutWidth = _landPhoneTips.bounds.size.width;
}
I spent hours dealing with this identical problem before finally sorting it out last evening. After changing the font size, you must select the UILabel within the storyboard and select Edit > Size to Fit Content, even if you had already previously done so! In doing so you apparently reset some setting that gets messed up when changing the font size. Once done, the UILabel will wrap as it did previously.

UILabel Fit Text Perfectly

I have a UILabel that needs to be set to multiple lines of text. I have set the noOfLines property to 0 and I have the following code:
self.aboutLabel.lineBreakMode = UILineBreakModeWordWrap;
self.aboutLabel.text = self.selectedVegetableCategory.about;
[self.aboutLabel sizeToFit];
The above code does make the text span multiple lines but still some of the text is missing. I am using CoreData to retrieve the text from db and the fields are varchar but they do not have any limit on it (I have not placed any limit on the number of characters). Does, varchar by default has a limit of number of characters?
UPDATE 1: I just checked again and this is definitely the UILabel issue since CoreData returns the complete text without truncation.
UPDATE 2: The original problem still exists and now there is a new problem. I put a new label just below the original label and now the new label does not move down when the original label expands.
What is the frame of the label before & after the call to sizeToFit?
I think that you'll have to provide it a specific frame if you want it to word wrap properly.

UITextView or UIWebView: How to display pages of a simple editable TXT file

All I want to have is a full-screen simple text editor. However, I don't want the scrolling component, but rather let the user flick through the pages (instead of scrolling). So I need to import or open a TXT and then format it by braking it down (e.g. by dividing its contents to 10 lines per screen/page).
My question is how I will display the txt? UITextView is scrollable (even though I can disable this in IB)... I did not find any method for UIWebView to let it format my contents on different 'pages' or screens.
Where will I need to start? Ideally I'd need some sample code. All the samples for UIWebView do not tell me anything about how to format editable text on several pages.
So all I really want is an UITextView which is not scrollable and opens up a new page/screen if I run out of space on the first page/screen.
Thanks for any help to get me started.
first thing first ...... there is no particular method to achieve this
1.You need to break your single string into multiple strings, to do that you can use
int pageNumber; // suppose this keep track of on what page you are
int count; //suppose this keep track of how long string your one screen support
NSString* completeString; //suppose this is your string
NSRange range = NSMakeRange(pageNumber * count, count);
NSString* temp = [completeString substringWithRange:range];
2.Now instead of using UITextView (if you don't want user interaction ) you should use UILable
just change the property of UILabel (this one is of your interest)
UILabel* myLabel; //suppose this is that label
myLabel.numberOfLines = 0; //this will chage your label to go multyline.
You should be able to achieve this by putting your UITextView into a UIScrollView and setting pagingEnabled on the UIScrollView to YES.

How to wrap the data in a label of a cell in iphone?

im passing huge data to a label of a cell.So i need to wrap the line.I tried the below methods ------- cell.textlabel.lineBreakMode = UILineBreakModeWordWrap; cell.textlabel.lineBreakMode =UILineBreakModeTailTruncation;By truncating the label also no use.In this way my problem didnt get solved.I want all the data to be displayed in the same font size also.If the label of a cell containg less data,the font size is different and if the label of a cell containing more data,the font size is small.Please help me out.....thanks in advance
you can find the uilabels expected size programetically and also appply the word wrap..please refer this.UILabel size according to text
there are two things you need to know when wrapping text to label.
1. numberOfLine on which you want to display the text
2. lineBreakMode.
most of the time we set numberOfLine = 0 when we need to wrap the text, but keep in mind that 0 indicate , uses as many line as needed to display the text. This will cause to push the label view beyond it's container view. So make sure you have used
cell.textLabel.numberOfLines=1;
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;

setting dynamic x coordinate of second lable in xcode objective c

i have a problem that i have two lables,
1) will contain a long text
2) this will be just More button (link)
so i want that when the first text ends then the second label starts right from where it end. but the problem is that the text is variable so i could not find any way to make it dynamic.
example
text of first row
"this is text of first label" "more"
text of second line
"test best" "more"
in the example the rows are of table view and two lables are separated by " so i want second label starting point from where the text in first lable ends
looking forward for some solution
Thanks & Regards!
NSString has some methods to calculate its size when displaying using given font (e.g. sizeWithFont: method) - you can use it to determine text width and place your more button accordingly (someZZZZ parameters must be available on runtime):
CGFloat firstLabelWidth = [firstLabel.text sizeWithFont:firstLabel.font].width;
CGFloat moreX = firstLabel.frame.origin.x + firstLabelWidth + someGap;
moreButton.frame = CGRectMake(moreX, moreY, someWidth, someHeight);
You may need to add some validation for cases when text in first label is too long to fit the screen etc, but in general this code should work.