NumberOfLines UILabel not working in cell

Everything,

I am very new to programming on iphone. In the following code, I want the text to display all the text in the comment label, but right now it truncates it. numberofLines does not work either. This is now being done. “My name is Fred and I'm dead ...”, but I want him to display the full text “My name is Fred, and I'm not dead yet, so let me live,” even if it should be on several lines.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80.0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; cell = [self.allCells objectForKey:[NSNumber numberWithInt:indexPath.row]]; if(!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"UserCell2" owner:nil options:nil] lastObject]; cell.backgroundColor = [UIColor clearColor]; cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; [self.allCells setObject:cell forKey:[NSNumber numberWithInt:indexPath.row]]; } GSAsynImageView *imgView = (GSAsynImageView*)[cell viewWithTag:1000]; UILabel *lblTitle = (UILabel*)[cell viewWithTag:1001]; UILabel *lblComment = (UILabel*)[cell viewWithTag:1003]; UILabel *lbltime = (UILabel*)[cell viewWithTag:1004]; //lblComment setLineBreakMode:NSLineBreakByWordWrapping]; //lblComment.numberOfLines = 0; //lblComment.lineBreakMode = UILineBreakModeCharacterWrap; if(self.arrComments.count==0) { imgView.hidden = YES; lblTitle.text = nil; lblComment.text = nil; lbltime.text = nil; if(indexPath.row==1)lblTitle.text = @"No comments yet"; } else { imgView.hidden = NO; NSDictionary *dcUser = [self.arrComments objectAtIndex:indexPath.row]; NSString *strBio = [dcUser objectForKey:@"CommentTxt"]; NSString *strDisplayName = [dcUser objectForKey:@"CommenterDisplayName"]; NSString *imgName = [dcUser objectForKey:@"ImageName"]; NSString *usernamex = [dcUser objectForKey:@"CommenterUserName"]; if([imgName isKindOfClass:[NSString class]]) { if([imgName rangeOfString:@"facebook"].location!=NSNotFound || [imgName rangeOfString:@"twimg"].location!=NSNotFound) [imgView loadImageFromPath:imgName]; else [imgView loadImageFromPath:[NSString stringWithFormat:@"%@images/%c/%@/50x50%@",WEBSERVER,[usernamex characterAtIndex:0],usernamex,imgName]]; } lblTitle.text = strDisplayName; lblComment.text = strBio; lbltime.text = [self getDateTitle:[dcUser objectForKey:@"Date"]]; } return cell; } 
+4
source share
6 answers

try this code below and add to your cell.

 UILabel * lblTitle = [[UILabel alloc]init]; [lblTitle setFrame:CGRectMake(110, 31, 200, 50)]; lblTitle.text = @"your Text "; lblTitle.lineBreakMode = UILineBreakModeWordWrap;// add this line lblTitle.numberOfLines = 0;// add this line lblTitle.font = [UIFont fontWithName:@"Helvetica" size:12]; 

For more details see my blog post with this post. THIS LINK

+3
source

try it...

 UILabel * label = [[UILabel alloc]init]; [label setFrame:CGRectMake(cell.frame.origin.x , cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)]; label.text = @" Text to be displayed in label "; label.lineBreakMode = UILineBreakModeWordWrap ;// Wrap at word boundaries label.numberOfLines = 0;// this line include multiple lines [cell addSubview:label]; 
+1
source

I think this is possible because the size of the line you want to show on the label exceeds the size of this label

0
source

You can use the UILabel properties to increase the number of rows. How UILabel* para = [[UILabel alloc]init];

 para.numberoOfLines = 10; 

and also try changing para.lineBreakMode

0
source

The easiest way to do this is in a storyboard or xib. You can add your label (and everything else you want) to a custom cell that you get automatically when you have a table view. Make sure your label has a certain width and that it has restrictions on the top and bottom of the cell (make sure you set the number of rows to 0). If you have, the label will expand with the height of the cell that you set in tableView: heightForRowAtIndexPath :.

0
source

Increase the height of the label and make the number of lines up to 2 for a specific label.

try this code

 lblComment.numberofLines = 2; [lblComment setFrame:CGRectMake(100,20,200,70)]; 
0
source

All Articles