user1498477
user1498477

Reputation:

How to make a scrollable view in iOS?

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?

Upvotes: 3

Views: 14223

Answers (5)

JAK
JAK

Reputation: 6491

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..

Upvotes: 2

Dayn Goodbrand
Dayn Goodbrand

Reputation: 611

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.

Upvotes: 1

Gabrail
Gabrail

Reputation: 220

There are two ways :

  • make settings bundel for your app check this Press Me

  • to make UITableView with custom cells >> it is easy if you use Interface Builder Press Me

Upvotes: 0

Madhu
Madhu

Reputation: 1542

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)];

Upvotes: 4

Durgaprasad
Durgaprasad

Reputation: 1951

Make only 1 nib file. give height of scroll view large as you want. then place your buttons , textfeild on scroll view

Upvotes: 0

Related Questions