Tuesday, June 4, 2013

UIScrollView contentSize example in Objective C (iOS).

UIScrollView contentSize

The size of the content view.

@property(nonatomic) CGSize contentSize

Discussion of [UIScrollView contentSize]
The unit of size is points. The default size is CGSizeZero.

UIScrollView contentSize example.
CGFloat scrollViewHeight = 0.0f;
for (UIView* view in scrollView.subviews)
   scrollViewHeight += view.frame.size.height;

[scrollView setContentSize:(CGSizeMake(320, scrollViewHeight))];

Example of [UIScrollView contentSize].
scrollView.scrollEnabled = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.showsVerticalScrollIndicator = YES;
[scrollView setFrame:CGRectMake(0, 30, 320, 380)];
CGSize srect =  CGSizeMake([scrollView bounds].size.width, (kNumImages * kScrollObjHeight));
[scrollView setContentSize:srect];
[self layoutScrollImages:YES];

UIScrollView contentSize example.
    [self performSelector:@selector(adjustScrollViewContentSize) withObject:nil afterDelay:0.1];

    _scrollView.contentSize = CGSizeMake(4000, 4000);

End of UIScrollView contentSize example article.