Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 379
HatAndBeard Avatar asked Jan 27 '26 16:01

HatAndBeard


1 Answers

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.

like image 163
Robert Kozak Avatar answered Jan 30 '26 09:01

Robert Kozak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!