HatAndBeard
HatAndBeard

Reputation: 1436

Setting bounds for a UIViewElement - Monotouch.Dialog

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?

Upvotes: 3

Views: 1526

Answers (1)

Robert Kozak
Robert Kozak

Reputation: 2033

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.

Upvotes: 3

Related Questions