2

I am using latest Monotouch 5.2.4. As part of my development, I am trying to change the background border of the Popover controller. As per apple documentation, this can be managed using a custom class inherited from UIPopoverBackgroundView class.

So I have created such class as below

public class MyPopoverBackground : UIPopoverBackgroundView
{
    public MyPopoverBackground ()
    {
        UIImageView imgBackground = new UIImageView();
        UIImage img = UIImage.FromFile(@"SupportData/Popbg.png");
        img.StretchableImage(18,10);
        imgBackground.Image = img;
        this.AddSubview(imgBackground);
    }   
}

After creation of this class, I am trying to associate this view with the Popup object I have in my view controller. It's defined as below

UIPopoverController popup = new UIPopoverController(searchPage);
popup.popOverBackroundViewClass = new MyPopoverBackground(); //This line throws compilation error

The last line in above code, where the assignment is happing throws compilation error ("does not contain definition for..").

What does this mean? Is this not supported in Monotouch (seems to be supported in Objective-C as I see many examples online)? Or I am missing something.

Appreciate your help.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Subhash Dike
  • 1,836
  • 1
  • 22
  • 37

1 Answers1

3

Good catch! It looks like a binding for popoverBackgroundViewClass (new in iOS5) is presently missing from MonoTouch.

I'll look into implementing it. If you want to fill a bug report at http://bugzilla.xamarin.com you'll be notified once this is done (just a quick bug report with a link to this question is enough). I should also be able to give you an hotfix or a workaround.

UPDATE

In MonoTouch 5.3+ (once released) you will be able to do something like:

popoverController.PopoverBackgroundViewType = typeof (MyPopoverBackgroundView);

Note that you cannot create your own instance since it needs to be done from the native side (hence why you only tell UIPopoverController which type to create).

You also need to follow all the requirements for UIPopoverBackgroundView which means exporting the required selectors (it's a bit more complex than simply inheriting since it requires static methods as well). E.g.

    class MyPopoverBackgroundView : UIPopoverBackgroundView {

        public MyPopoverBackgroundView (IntPtr handle) : base (handle)
        {
            ArrowOffset = 5f;
            ArrowDirection = UIPopoverArrowDirection.Up;
        }

        public override float ArrowOffset { get; set; }

        public override UIPopoverArrowDirection ArrowDirection { get; set; }

        [Export ("arrowHeight")]
        static new float GetArrowHeight ()
        {
            return 10f;
        }

        [Export ("arrowBase")]
        static new float GetArrowBase ()
        {
            return 10f;
        }

        [Export ("contentViewInsets")]
        static new UIEdgeInsets GetContentViewInsets ()
        {
            return UIEdgeInsets.Zero;
        }
    }
poupou
  • 43,413
  • 6
  • 77
  • 174
  • Thanks for your prompt response. I have filled a bug as you mentioned. I am happy to see that SO is being closely watched and responded by the very same product team. Keep it up.. – Subhash Dike Feb 17 '12 at 05:45