How to make a rootViewController scroll?

JohanSundstrmJohanSundstrm SEMember, University

Hi,
I made a custom UIViewController that I add to the window.RootViewController (in AppDelegate.cs). The content in my CustomViewController doesent fit in the windows so I want it to scroll.

I tried to make use UIScrollView in differrent ways but I cant figure it out how to use it...

Some example please

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    This belongs in the iOS forum.

    Anyways you want a UIScrollView so try to explain what you have tried and what results you are seeing.

  • JohanSundstrmJohanSundstrm SEMember, University

    Asimple example that dont work!

    ------------AppDelegate.cs---------------------------------------
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using MonoTouch.Foundation;
    using MonoTouch.UIKit;

    namespace scroll__test
    {

    [Register("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
    
        UIWindow window;
    
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
    
            window = new UIWindow(UIScreen.MainScreen.Bounds);
    
            CustomViewController controller = new CustomViewController();
            window.RootViewController = controller;
    
            window.MakeKeyAndVisible();
    
            return true;
        }
    }
    

    }

    ------------CustomViewController.cs--------------------------------
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using MonoTouch.UIKit;

    namespace scroll__test
    {
    class CustomViewController:UIViewController
    {
    UIScrollView scrollview;
    UIButton btn;
    public override void ViewDidLoad()
    {
    base.ViewDidLoad();
    View.BackgroundColor = UIColor.White;
    scrollview = new UIScrollView
    {
    Frame=new RectangleF(0, 0, View.Frame.Width, View.Frame.Height),
    ScrollEnabled = true
    };

            for (int i = 1; i < 20; i++)
            {
                btn = new UIButton();
                btn = UIButton.FromType(UIButtonType.RoundedRect);
                btn.Frame = new RectangleF(30, 20 + 30 * i, View.Frame.Width - 60, 30);
                btn.SetTitle("Button " + i.ToString(), UIControlState.Normal);
                scrollview.AddSubview(btn);
            }
            View.AddSubview(scrollview);
        }
    }
    

    }

  • JohanSundstrmJohanSundstrm SEMember, University

    The formatting was not well, attach the project instead.

  • CheesebaronCheesebaron DKInsider, University mod

    What does not work. You are not helping by just dumping code and not describing the symptoms or errors!

  • CheesebaronCheesebaron DKInsider, University mod
    edited August 2013

    Anyways your problem is that you did not set the ContentSize on the UIScrollView. Please refer to the documentation and samples for how to use that.

  • JohanSundstrmJohanSundstrm SEMember, University

    Sorry,
    there is no errors but it also no scroolbar.
    I just done the small example (it's a code only project) so someone could compile and run it and see it for your self. God point with the ContentSize ve will try how to set that.
    Ive tried so find some dokumentation/samples for hours, do you know some link?

    Thanks in advance!

  • JohanSundstrmJohanSundstrm SEMember, University

    The ContentSize did it :-)

    Thanks a lot

Sign In or Register to comment.