0

我有以下从 Xamarin MobileCRM 示例改编的代码:

[assembly: ExportCell(typeof(ListTextCell), typeof(ListTextCellRenderer))]

namespace Manager.iOS
{
class ListTextCellRenderer : TextCellRenderer
{
    public override UITableViewCell GetCell(Cell item, UITableView tv)
    {
        var cellView = base.GetCell(item, tv);
        cellView.TextLabel.Lines = 0;                        
        return cellView;
    }               
}
}

我希望当 TextLabel 包含的文本多于设备宽度时,它会拉伸/换行,因此行的大小会随之增长。当我设置 Lines = 0; 它包装了标签,但行高保持不变,所以每一行只是相互重叠。我如何增加行高?

谢谢

4

2 回答 2

1

在您的 tableView 源代码中,您将要覆盖以下方法

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
    var text = new NSString(yourTextHere);
    var size = text.StringSize(UIFont.FromName("FontName", fontSize), new SizeF(tableView.Frame.Width, 70)); // The 70 can be any number, the width is the important part
    return size.Height + 16; // 16 is for padding
 }
于 2014-08-01T14:13:11.363 回答
0

您可能必须在 TableView 上设置 HasUnevenRows 或 RowHeight

于 2014-07-31T15:29:16.157 回答