How to make a scrollable view in iOS?

14,113

Solution 1

Use ContentSize property of UIScrollView to scroll what ever area you want. i.e.

take UIScrollView add it on UIView with exist height of iPhone. i.e. max 460.0 So ScrollView frame will be max (0,0,320.0,460.0).

Now after adidng ScrollView to View set ContentSize property to upto scrollable area.

[self.mainScrollView setContentSize:CGSizeMake(self.mainScrollView.frame.size.width, 1000.0)];

Solution 2

UIScrollView *mainScroll = [[[UIScrollView alloc]initWithFrame:CGRectMake(x,y,w,h)]autorelease];//scrollview width and height

mainScroll.scrollEnabled = YES;   
mainScroll.userInteractionEnabled = YES;

mainScroll.showsVerticalScrollIndicator = YES;

mainScroll.contentSize = CGSizeMake(width,height);//width and height depends your scroll area

..........

//add  subviews to your scrollview.....
[mainScroll addSubview:view1]

............

[mainScroll addSubview:view2]

..............

[mainScroll addSubview:view3]

[self.view addSubview:mainScroll];

Note :: contentSize property determines your scroll area.Scrolling enabled only if your scrollview content larger than scrollview height..

Solution 3

You could use a Table View with static Cells, that will scroll automatically if it needs to, much easier. Also with a Table View you can choose to scroll up, down, left, right, set bouncing etc from the Attributes Inspector.

Share:
14,113

Related videos on Youtube

Admin
Author by

Admin

Updated on September 14, 2022

Comments

  • Admin
    Admin almost 2 years

    i am looking to create an "options" page for my application and because they are many , the screen of the phone is not enough to show.

    So i need the user to be able to scroll down the view to see more options till the last. I know i should use the scrollview , but i dont know how.

    All the tutorials i ve found are about scrolling all over the screen , zooming , scrolling from left to right , but nothing on how u can create a simple page scrolling up and down.

    How exactly do i do that? Do i make many .nib files and somehow i connect them? Do i make a big .nib file?

    Can someone guide me to a tutorial on that?

    • trojanfoe
      trojanfoe over 11 years
      It might be as easy as subclassing UIScrollView rather than UIView?