Reputation: 2309
I am trying to implement a horizontal uiscrollview. I want the user to the be able to swipe to the next view and I am not concerned about the user knowing what page they are on (there are only 2 views). I believe they call this page control.
So in my IB I have a default view which then I have added a UIScrollView into it and linked its referencing outlet (called scrollView). I have put all the UILabels and images that were previously in the default view into the scrollView.
I then created another empty view by dragging it into IB and linked it as well calling it newView. It is a separate object and not put into the default view.
Then in my view controller viewDidLoad I use the following code:
[self->scrollView setScrollEnabled:YES];
[self->scrollView setDelegate:self];
self->scrollView.backgroundColor = [UIColor clearColor];
[self->scrollView setShowsHorizontalScrollIndicator:NO];
[self->scrollView setIndicatorStyle:UIScrollViewIndicatorStyleDefault]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.contentMode = UIViewContentModeScaleToFill;
[self->scrollView setContentSize:CGSizeMake(1300.0,0)];
[self.view addSubview:scrollView];
It does not work. Can anyone explain what I am doing wrong?
Thanks!
Upvotes: 1
Views: 1895
Reputation: 5267
The answer provided by @V-Xtreme is right but missing one thing and is the paging which is mentioned in question by PO :)
So for paging enabled there are two ways:
[self->scrollView setPagingEnabled:YES];
Paging Enabled
option ie. make sure that it is checked.Upvotes: 0
Reputation: 7333
Just remove following line from your code:
[self->scrollView setShowsHorizontalScrollIndicator:NO];
Also you don't required :
[self->scrollView setIndicatorStyle:UIScrollViewIndicatorStyleDefault]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
And add
[self->scrollView setContentSize:CGSizeMake(1300.0,200.0)];
Also set xib to its default settings
Try this this should work.
Upvotes: 2