How to wrap the data in a label of a cell in iphone? - 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;

Related

Large text not displaying as multiple lines for UILabel in a custom tableview cell

Setting up the UILabel on the attributes inspector as follow expands the cell and display the large text as multiple lines correctly for a Subtitle tableview cell:
Lines = 0
Line Break = Word wrap
But this doesn't work in a custom tableview cell for some reasons. In the custom cell, I added new labels and setup the attributes the same way but the cell doesn't expand.
It could be a matter of constraint.
Check to see if there are any conflicting constraints or fixed settings.
In order for elements of a cell to be set flexibly, the height of the cell must be set to the automatic value.
When I set it up like this, I was able to get the results I wanted.

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.

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

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

UITableview to autowrap long text

How can I get a UITableView to automatically wrap text which is longer than the width of the cell?
You need to dynamically determine the height of the cell, and set your label so that it autosizes itself. There's a fairly comprehensive explanation here: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
Set the "setNumberOfLines" property of the label to wrap the text to required number of lines. If you don't want the .... at the end of the text if it is too long then
label.lineBreakMode = UILineBreakModeWordWrap;
or if you want to show the ... after the text then don't use the above code.
All the best.
See the options for the lineBreakMode of the UILabel inside the UITableViewCell here.
hth
–f