动态添加自定义单元格内的标签

时间:2015-04-15 11:17:50

标签: ios uilabel custom-cell

我在自定义单元格中动态添加UIlabels,每个标签之间的间隙未正确对齐。所以,请帮我解决此问题。

 cell.lblObj.numberOfLines=0;
 cell.lblObj.lineBreakMode = NSLineBreakByWordWrapping;
 CGSize maximumLabelSize = CGSizeMake(170,100);
 CGSize expectedLabelSize = [strfrom sizeWithFont:cell.lblObj.font
                                   constrainedToSize:maximumLabelSize
                                       lineBreakMode:NSLineBreakByWordWrapping];
 CGRect newFrame = cell.lblObj.frame;
 newFrame.size.height = expectedLabelSize.height;
 cell.lblObj.frame = newFrame;
 cell.lblObj.text=strfrom;
 [cell.lblObj sizeToFit];

Please Check this screen

 NSString *strfrom=[[mtblarray objectAtIndex:indexPath.row] valueForKey:@"source"];
 cell.lblfrom.numberOfLines=0;
 cell.lblfrom.lineBreakMode = NSLineBreakByWordWrapping;
 CGSize maximumLabelSize = CGSizeMake(170,100);
 CGSize expectedLabelSize = [strfrom sizeWithFont:cell.lblfrom.font
                                   constrainedToSize:maximumLabelSize
                                       lineBreakMode:NSLineBreakByWordWrapping];
 CGRect newFrame = cell.lblfrom.frame;
 newFrame.size.height = expectedLabelSize.height;
 cell.lblfrom.frame = newFrame;
 cell.lblfrom.text=strfrom;
 [cell.lblfrom sizeToFit];
 cell.lblfrom.backgroundColor = [UIColor redColor];

1 个答案:

答案 0 :(得分:1)