public void AddSquare(SquareView view)
        {
            AddSubview(view);

            var childCount  = AccessibilityChildren.Length;
            var newChildren = new NSObject[childCount + 1];

            if (childCount > 0)
            {
                Array.Copy(AccessibilityChildren, newChildren, childCount);
            }

            newChildren[childCount] = view;

            AccessibilityChildren = newChildren;

            int maxX, maxY;

            maxX = (int)(Frame.Width - view.Frame.Width);
            maxY = (int)(Frame.Height - view.Frame.Height);

            int x, y;

            x = rnd.Next(maxX);
            y = rnd.Next(maxY);

            CGRect sqFrame = new CGRect(x, y, view.Frame.Width, view.Frame.Height);

            view.Frame = sqFrame;
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Do any additional setup after loading the view.

            for (int i = 0; i < 10; i++)
            {
                var v = new SquareView();
                v.Frame   = new CoreGraphics.CGRect(0, 0, 20, 20);
                v.Color   = NSColor.FromRgb((256.0f / i) / 256.0f, 0, 0);
                v.AltText = $"Square {i}";

                container.AddSquare(v);
            }
        }