MonoTouch.Dialog.PagingViewController.LoadView C# (CSharp) Method

LoadView() public method

public LoadView ( ) : void
return void
        public override void LoadView()
        {
            baseView = new UIView(UIScreen.MainScreen.Bounds);

            scrollView = new UIScrollView(new RectangleF(0,0,baseView.Bounds.Width,baseView.Bounds.Height-36)) {
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin,
                AutosizesSubviews = true,
                PagingEnabled = true,
                ShowsHorizontalScrollIndicator=false,
                ShowsVerticalScrollIndicator=false
            };

            pageControl = new UIPageControl(new RectangleF(0,baseView.Bounds.Height-36,baseView.Bounds.Width,36));

            pageControl.ValueChanged += delegate(object sender, EventArgs e) {
                var pc = (UIPageControl)sender;
                double fromPage = Math.Floor((scrollView.ContentOffset.X - scrollView.Frame.Width / 2) / scrollView.Frame.Width) + 1;
                var toPage = pc.CurrentPage;
                var pageOffset = scrollView.Frame.Width*toPage;
                Console.WriteLine("fromPage " + fromPage + " toPage " + toPage);
                PointF p = new PointF(pageOffset, 0);
                scrollView.SetContentOffset(p,true);
            };

            CreatePanels();

            baseView.AddSubview(scrollView);
            baseView.AddSubview(pageControl);

            View = baseView;
        }

Usage Example

        // This method is invoked when the application has loaded its UI and its ready to run
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // If you have defined a view, add it here:
            // window.AddSubview (navigationController.View);

            PagingViewController pgVC = new PagingViewController(true);

            pgVC.LoadView();

            window.Add(pgVC.View);

            window.MakeKeyAndVisible ();

            return true;
        }