How do I make a scrollable view in iOS?

I want to create a Settings page for my application and since there are a lot of them, the phone screen is not enough to show.

So I need the user to be able to scroll down the view to see more options until the last one. I know I should be using scrollview, but I don't know how.

All the tutorials I've found are about full screen scrolling, zooming, left to right scrolling, but nothing about how you can create simple page up and down scrolling.

How exactly do I do it? Am I making a lot of .nib files and connecting them somehow? Am I making a large .nib file?

Can anyone lead me to a tutorial?

+3


source to share


5 answers


Use the ContentSize

property UIScrollView

to scroll to any area you want. those.

take UIScrollView

add it on UIView

with iPhone height. those. Max. 460.0 Thus, the frame ScrollView

will be the maximum (0,0,320,0,460.0).



Now after adidng ScrollView

to View

set the property ContentSize

to scrollable area.

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

      

+3


source


You can use a table view with static cells, which will automatically scroll if needed, much easier. Also with Table View you can scroll up, down, left, right, set bounce, etc. From the Attribute Inspector.



+1


source


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 :: the contentSize property defines your scroll area.Scrolling is enabled only if your scroll content is larger than the scroll height.

+1


source


Make only 1 nib file. give the scroll view height as large as you want. then put your buttons, textfeild in scroll mode

0


source


There are two ways:

  • make settings for your application, check it Press Me

  • make UITableView with custom cells -> it's easy if you are using Interface Builder Press Me

0


source







All Articles