Vipin
Vipin

Reputation: 4728

How can generate Vertical scrolling?

i am using the below code to create scroll view.however its showing horizontally. can any one tell me how can i change this scroll view to vertical way.

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(25,50,700,175)];
[self.view addSubview:scrollView1];
[scrollView1 setBackgroundColor:[UIColor lightGrayColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES;        // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled=YES;

Upvotes: 1

Views: 2019

Answers (4)

Learning Programming
Learning Programming

Reputation: 476

The scrolling of an any scroll view is totally depends on the contentSize property. Here in your code you have not mentioned the content size for your scrollView1.

So, you should add this,

scrollView1.contentSize = CGSizeMake(700, 1750);

Here we provided two parameters one is width and other is height. This gives 10 times vertical scrolling because your frame height is of 175 pixels and contentSize height is of 1750 pixels.

Note : Your contentSize values i.e. width and height must be greater than frame size for scrolling purpose.

Thank you...

Upvotes: 0

ManjotSingh
ManjotSingh

Reputation: 711

As your code is working for the horizontal scrolling ,you just need set initWithFrame .Below code will be help full for you and rest of the code will be same vertical scrolling will be started

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(25,50,175,700)];

Upvotes: 0

Felipe Sabino
Felipe Sabino

Reputation: 18225


The scrolling of a UIScrollView is based on the contentSize property, which is a CGSize value.

Whenever the width or height are bigger than the scroll view frame, the scroll view will allow the scrolling (if the properties showsVerticalScrollIndicator, showsHorizontalScrollIndicator and scrollEnabled are all set to YES - which are the default values)

So, one thing that you can try to do is setting the height of your contentSize bigger than the one already set as your frame, for example:

scrollView1.contentSize = CGSizeMake(700, 300);

Upvotes: 2

bdparrish
bdparrish

Reputation: 2774

Also check your autoRotate function is returning the correct layout. If you have do not tell your application that it can rotate view to portrait, then it will stay in the horizontal configuration, which you have hardcoded.

Upvotes: 0

Related Questions