Set the starting point of the horizontal UIScrollView

I have tried many different solutions, but none of them work for me.

I have a horizontal scroll view, now it starts on the left, but how can I launch it in the middle?

I am using this code right now in the controller:

- (void)viewDidLoad { [scroller2 setScrollEnabled:YES]; [scroller2 setContentSize:CGSizeMake(1735, 300)]; [super viewDidLoad]; } 

and IBOutlet UIScrollView *scroller2; in the header file.

I made the content in the interface builder (.xib file) and I am using Xcode 4.2!

Thanks in advance!

+4
source share
2 answers

I think you need to call scrollRectToVisible:animated:

try this in viewDidLoad or viewDidAppear or sth. similarly.

  [scroller2 scrollRectToVisible:CGRectMake(1735/2.0, 300/2.0, 1,1) animated:NO] 
+2
source

You are looking for the contentOffset property.

 [scroller2 setContentOffset:CGPointMake(appropriateXDisplacement, 0)]; 
+4
source

All Articles