UILabel里面的UITableViewCell.在单元格点击上,高度会扩展,并且会UILabel出现一个包含各种数据量的高度.
问题是,如果换行,sizeWithFont:constrainedToSize:lineBreakMode:则不会返回适当的高度并切断底线.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
labelExpanded = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
labelExpanded.font = [UIFont boldSystemFontOfSize:11];
labelExpanded.textAlignment = UITextAlignmentLeft;
labelExpanded.lineBreakMode = UILineBreakModeWordWrap;
labelExpanded.numberOfLines = 0;
[cell.contentView addSubview:labelExpanded];
CGSize constraint = CGSizeMake(300, 20000);
CGSize size = [expandedDetails sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[labelExpanded setText:expandedDetails];
[labelExpanded setFrame:CGRectMake(16, 30, 248, size.height)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(// Row is Expanded)
{
CGSize constraint = CGSizeMake(300, 20000);
CGSize size = [sameTextAsLabel sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
// I found +8 to height added nice padding
CGFloat height = size.height + 8;
}
else // Row is not expanded
return 30;
}
Run Code Online (Sandbox Code Playgroud)
同一文本被送到两者,它由一个包含多个新行的字符串组成\n.如果该行长于宽度,则自动换行完成其工作,但在计算其动态高度时,它无法包含换行.
如果我添加任何值,[labelExpanded setFrame:height]如[size.height + 30]我的包裹线显示.但是,如果未包装该行,则会添加不必要的空格.
我无法在网上找到解决方案.
| 归档时间: |
|
| 查看次数: |
5043 次 |
| 最近记录: |