我在自定义单元格中动态添加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];
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];
答案 0 :(得分:1)