gpt4 book ai didi

uitableview - 单点触控 : UITableViewCell height

转载 作者:行者123 更新时间:2023-12-02 00:27:27 25 4
gpt4 key购买 nike

我一直在网上冲浪,想弄清楚如何让我的表格单元高度适合它的内容(我的内容高度不同)。

我试过查看这个样本.... http://simon.nureality.ca/simon-says-project-d-uitableviewcells-autosize-based-on-text-height-in-monotouch-heres-how/......但我无法让它发挥作用。

到目前为止,这是我的代码。单元格高度实际上有效,但文本以尾随点为中心(而不是钻出整个框架):

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
string item = this.Lst.Items [indexPath.Section];

UITableViewCell cell = tableView.DequeueReusableCell (_cellIdentifier);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, _cellIdentifier);
cell = new UITableViewCell (UITableViewCellStyle.Subtitle, _cellIdentifier);
}

// Find the height...
SizeF textWidth = new SizeF (tableView.Bounds.Width - 40, float.MaxValue);
SizeF textSize = tableView.StringSize(item, Font, textWidth, LineBreakMode);

// Textlabel...
cell.TextLabel.Text = item;
cell.TextLabel.Font = Font;
cell.TextLabel.Frame = new RectangleF(cell.TextLabel.Frame.X, cell.TextLabel.Frame.Y, textSize.Width, textSize.Height);

//cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
cell.ImageView.Image = PlaceholderImage;
cell.EditingAccessory = UITableViewCellAccessory.DisclosureIndicator;

// Sizing the cell...
RectangleF rectCell = cell.Frame;
rectCell.Height = textSize.Height;
cell.Frame = rectCell;

return cell;
}

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
string item = this.Lst.Items [indexPath.Section];
SizeF size = new SizeF (tableView.Bounds.Width - 40, float.MaxValue);
float height = tableView.StringSize (item, Font, size, LineBreakMode).Height + 10;
return height;
}

它看起来像这样......

enter image description here

知道哪里出了问题吗?

谢谢!

魔力

最佳答案

您可以通过设置 LinesLineBreakMode 属性来控制文本标签的行为。

例如设置

cell.TextLabel.Lines = 0;
cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;

会让您的标签自动换行并根据需要使用尽可能多的行。

也可以考虑使用 MonoTouch.Dialog米格尔·德·伊卡萨 (Miguel De Icaza)。它大大简化了 UITableView 的处理。

关于uitableview - 单点触控 : UITableViewCell height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8344596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com