Can someone explain to me what the contentInset property in a UIScrollView
instance is used for? And maybe provide an example?
Great question.
Consider the following example (scroller
is a UIScrollView):
float offset = 1000;
[super viewDidLoad];
for (int i=0;i<500; i++) {
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(i * 100, 50, 95, 100)] autorelease];
[label setText:[NSString stringWithFormat:@"label %d",i]];
[self.scroller addSubview:label];
[self.scroller setContentSize:CGSizeMake(self.view.frame.size.width * 2 + offset, 0)];
[self.scroller setContentInset:UIEdgeInsetsMake(0, -offset, 0, 0)];
}
The insets are the ONLY way to force your scroller to have a "window" on the content where you want it. I'm still messing with this sample code, but the idea is there: use the insets to get a "window" on your UIScrollView
.