3

我正在尝试在 UIViewElement 中显示 UITextView。我希望元素根据文本调整自身大小。

我期待能够做这样的事情......

 UITextView textView = new UITextView();



    textView.Font = UIFont.SystemFontOfSize(15);
       var stringSize = textView.StringSize(someArbitraryText, 
                                            textView.Font, 
                                            new SizeF(320, 2000), 
                                            UILineBreakMode.WordWrap);

       textView.Bounds = new RectangleF(0,0,stringSize.Width, stringSize.Height);          
       textView.Center = new PointF(stringSize.Width/2, stringSize.Height/2);
       textView.Editable = false;
       textView.DataDetectorTypes = UIDataDetectorType.All;
       textView.Text = someArbitraryText;
       textView.ScrollEnabled = false;       





   root.Add(
      new Section("My Section:")
      {

         new UIViewElement("My Caption:", textView, false),

      });

这让我很接近,但我的 UITextView 的一部分超出了元素边界。我希望 UIViewElement 的大小足够大以适合我的自定义视图。有没有办法在不进入和修改 UIViewElement 源的情况下做到这一点?

4

1 回答 1

3

在您的元素中添加 IElementSizing 的实现,我相信该方法是:

float GetHeight(UITableView tableView, NSIndexPath indexPath);

在此方法中返回元素的高度。即TextView.Bounds.Height + 10。我为顶部和底部的边框添加了+ 10。

于 2011-03-31T20:18:37.993 回答