|
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 26
|
Hi,
I am adding a label in my custom tableviewcell. But the text is too long to fit in a single line.So i want it to be wrapped on to the next line. I used lineBreakMode as UILineBreakModeWordWrap and also set the numberOfLines to 0. But the text was cut off. My actual text is This is a sample text for a label Before setting these properties the output was like This is a sample text for... And after setting the properties it comes out to be This is a sample text for Actually i cannot increase the width for the label due to my app design, so i have to display it on multiple lines. Please let me know if i need to set some other properties or change the existing to some other values.. Thanks, Akshay. |
|
|
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 26
|
Hi wyvwyv,
Here my code snippet that does the thing... mainText = [self newLabelForMainText:YES setSizeFor:1]; mainText.textAlignment = UITextAlignmentLeft; [self addSubview:mainText]; [mainText release]; - (UILabel *)newLabelForMainText BOOL)main setSizeFor NSInteger)sizeFor{ ... newLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,2,200,30)]; newLabel.lineBreakMode = UILineBreakModeWordWrap; newLabel.numberOfLines = 0; newLabel.opaque = YES; newLabel.textColor = primaryColor; newLabel.highlightedTextColor = selectedColor; newLabel.font = font; .. return newLabel; } Please help me out for this.. Actually the text fits in if i reduce the font size. But i dont want to do that... |
|
|
|
|
|
#5 (permalink) |
|
Member
Join Date: Jun 2008
Posts: 56
|
Here is code I use that wraps the text in the label just fine.
Code:
You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor. labelInstructions = [[UILabel alloc] initWithFrame:CGRectMake(20,20,240,200)]; labelInstructions.font = [UIFont systemFontOfSize: 16]; labelInstructions.lineBreakMode = UILineBreakModeWordWrap; labelInstructions.numberOfLines = 0; labelInstructions.backgroundColor = [UIColor clearColor]; labelInstructions.text = @"..long text string.."; [self.view addSubview:labelInstructions]; |
|
|
|
|
|
#6 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 26
|
hi wyvwyv,
It was the same what you said... that the label's vertical height was small.. however my font size was 15 but still it was giving problem. Now i changed the label height to 40 and the wrapped text is shown... However is it possible that my cell height would be changed according to the height of the text in that cell.. I mean if text fits in a single line then the row size would be for single line, however if the text is wrapped to 2 or 3 lines then the row height is changed accordingly. The reason i need this is that if i have 3 rows in my table out of which only 1 row has wrapped text of 3 lines then the other two rows have lots of free space which looks very bad... Thanks... |
|
|
|
|
|
#7 (permalink) |
|
Member
Join Date: Jun 2008
Posts: 56
|
So these labels are going inside of UITableCellViews? And you want to make the height of the table cell appropriate to the height of the text?
Not simple, but I think it is possible. You'll need to subclass UITableCellView (which I'm guessing you've done). The table itself should have a delegate with the tableView:heightForRowAtIndexPath method. This method is what you use to set the height for each row. What you also need is an array of your subclassed UITableCellViews somewhere (which is what you would use to populate the table in the tableView:cellForRowAtIndexPath: method). The subclassed table cell must have a public member or property that says how much height that cell will want. You can use the textRectForBounds:limitedToNumberOfLines: of the UILabel to get the drawing rectangle of the label. Use the height component of that size to determine the height required, and pass it back to the table delegate that determines the height of the cell. |
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.3.0 RC1 |




BOOL)main setSizeFor
Linear Mode
