Monotouch对话框多行元素高度没有增长

Posted

技术标签:

【中文标题】Monotouch对话框多行元素高度没有增长【英文标题】:Monotouch dialog multiline element height not growing 【发布时间】:2013-02-04 13:55:15 【问题描述】:

我有一个简单的自定义多行元素,我将其换行模式设置为自动换行,并将行属性设置为 7。我的文本似乎可以很好地换行,但单元格高度保持不变,因此文本扩展了边界的细胞。我尝试增加单元格的框架并覆盖 GetHeight,但在这两种情况下似乎都不起作用。另外,我的 GetHeight 似乎没有被调用。

任何人都面临类似的事情?或者对可能出现的问题有什么想法?

public class DisclaimerMultilineElement : MultilineElement

    public DisclaimerMultilineElement (string caption) : base(caption)
    
    

    public DisclaimerMultilineElement (string caption, string value) : base(caption, value)
    
    

    public DisclaimerMultilineElement (string caption, NSAction tapped) : base(caption, tapped)
    
    

    public override float GetHeight (UITableView tableView, NSIndexPath indexPath)
    
        var ht = base.GetHeight (tableView, indexPath);
        //return base.GetHeight (tableView, indexPath);
        return 400.0f;
    

    public override UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv)
    
        UITableViewCell cell = base.GetCell (tv);
        var frame = cell.Frame;
        frame.Height = 300f;
        //cell.Frame = new System.Drawing.RectangleF(frame.X, frame.Y, frame.Width, frame.Height);
        cell.BackgroundColor = UIColor.Clear;
        cell.TextLabel.Font = UIFont.BoldSystemFontOfSize (12);
        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
        cell.TextLabel.Lines = 7;
        cell.TextLabel.TextAlignment = UITextAlignment.Left;
        cell.TextLabel.Text = Value;
        return cell;
    

【问题讨论】:

【参考方案1】:

确保在您的 Root 元素中将 UnevenRows 设置为 true

【讨论】:

【参考方案2】:

您需要在您的UITableViewSource 中覆盖GetHeightForRow 并返回适当的高度。

【讨论】:

以上是关于Monotouch对话框多行元素高度没有增长的主要内容,如果未能解决你的问题,请参考以下文章

多行 UILabel 高度,横向自动布局更高

MonoTouch:添加 UIImageView 后 UITableViewCell 更改高度

水平stackview标签随着固定高度元素增长

垂直居中-父元素高度确定的多行文本(方法一)

UITableViewCell 中带有多行标签的 UIStackView 高度不正确

垂直居中-父元素高度确定的多行文本(方法二)