为UIViewElement设置边界 - Monotouch.Dialog

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足够大以适应我的自定义视图。是否有方法可以在不修改UIViewElement源代码的情况下完成此操作?

1个回答

3
在您的Element中添加一个IElementSizing的实现,我相信方法是:
float GetHeight(UITableView tableView, NSIndexPath indexPath);
在此方法中返回元素的高度。即TextView.Bounds.Height + 10。我添加了+10个边框,上下都有。

2
我希望能够在不使用UIViewElement的情况下完成这个任务,但我注意到(来自MonotoTouch.Dialog的)ActivityElement也做了同样的事情。看起来UIViewElement本身并不能真正地使用。 - HatAndBeard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接