3

I'm trying to Display a UITextView in an UIViewElement. I would like the Element to size itself to the text.

I am expecting to be able to do something like this...

 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),

      });

This gets me close, but leaves parts of my UITextView over the Element boundary. I would like the UIViewElement to be sized large enough to fit my custom view. Is there a way to this without going in and modifying the UIViewElement source?

HatAndBeard
  • 1,416
  • 3
  • 18
  • 31

1 Answers1

3

In your Element add an Implementation for IElementSizing, I believe the method is:

float GetHeight(UITableView tableView, NSIndexPath indexPath);

In this method return the Height of the Element. ie TextView.Bounds.Height + 10. I added the + 10 for a border on top and bottom.

Robert Kozak
  • 2,043
  • 17
  • 33
  • 2
    I was hoping to do this without subclassing the UIViewElement, but I noticed ActivityElement (from MonotoTouch.Dialog) did the same thing. It seems UIViewElement isn't really usable on its own. – HatAndBeard Apr 01 '11 at 15:21