Hello dave!
And that’s what’s frustrating, every time I read something about that topic I always get a simple solution that doesn’t work for me. And since I’ve never done anything using UIView I am super lost in this.
So let me post some code.
This is my UIView Class that I am trying to draw on top of my game:
public class myUiView : UIView
{
public myUiView () : base() { }
// rect changes depending on if the whole view is being redrawn, or just a section
public override void Draw (RectangleF rect)
{
//Console.WriteLine (“Draw() Called”);
base.Draw (rect);
using (CGContext context = UIGraphics.GetCurrentContext ()) {
// fill the background with white
// set fill color
UIColor.White.SetFill ();
//context.SetRGBFillColor (1, 1, 1, 1f);
// paint
context.FillRect (rect);
// draw a rectangle using stroke rect
UIColor.Blue.SetStroke ();
context.StrokeRect (new RectangleF (10, 10, 200, 100));
// draw a rectangle using a path
context.BeginPath ();
context.MoveTo (220, 10);
context.AddLineToPoint (420, 10);
context.AddLineToPoint (420, 110);
context.AddLineToPoint (220, 110);
context.ClosePath ();
UIColor.DarkGray.SetFill ();
context.DrawPath (CGPathDrawingMode.FillStroke);
// draw a rectangle using a path
CGPath rectPath = new CGPath ();
rectPath.AddRect (new RectangleF (new PointF (430, 10), new SizeF (200, 100)));
context.AddPath (rectPath);
context.DrawPath (CGPathDrawingMode.Stroke);
}
}
It is basically the simplest UIView class from the Drawing sample on the xamarin sambles. I took one from there since I didn’t really know how exactly how to make one of those.
And after that I create a static reference to the RootUIController using the code that you suggested and called the draw function in the middle of a spritebatch call.
But it simply does not show anything all I got is the image that I am drawing on the spritebatch. At this point I started to think that something went wrong or that this code doesn’t work anymore, so I researched a little bit more and I got this code here:
UIApplication.SharedApplication.Windows[0].RootViewController.View.Addsubview(uiView);
But still no white rectangles on my screen. But hey! There are still some more codes that I can try:
UIApplication.SharedApplication.Windows[0].RootViewController.MakeKeyAndVisible();
or even trying to add on Windows[1], but nothing seems to work.
So am I doing something wrong?
Could you pleeeease help me out on this?