UIScrollView settings page size dynamically

I looked at it a bit, but could not find a solution.

I have a UIScrollView called scrollView inside a UIView . I am using this scrollView in pagingEnabled mode. Inside scrollView , I have 3 different views created programmatically. Inside these three different views, I have a bunch of things ( UILabel, UITextView, etc. ). The entire contents of the views is dynamic and is determined at runtime. So I really don't know scrollView.contentSize . If I give the content size of this scrollView , sometimes I have a screen with a white space on the screen of the screen when the user scrolls down. My question is: Can i set the content size dynamically for each single page of this scrollView ? For example, for page 1:

self.scrollViewNews.contentSize = CGSizeMake(constant1,constant2);

And install something else for page 2.

+4
source share
5 answers

I think you are confused about contentSize compared to swap size. The size of the search call is always the size of the scrollView borders and is not a property that you can otherwise set. That is, when scrolling left / right, it will be a "page" in the width of the scroll.

contentSize is the size of the virtual bounding box of all the subzones in the scroll. This only serves to limit how the scroll scroll scrolls, and to swap how many times it will be on the page, i.e. contentSize.width / bounds.size.width .

Assuming scrollView does not scale to / from (zoomScale = 1.0), you also need to position the size of your subzones on the virtual borders of the pages. They can handle the entire border of the page (the size must match scrollview.bounds) or be an insert. If you have content that is larger / smaller, you will have to decide whether you want to scale this content or to scale it up / down within the page.

+3
source

Yes, you can dynamically set the scrollView content size. You can also use this method:

 self.scrollViewNews.contentSize = CGSizeMake(constant1,constant2); 

Nothing wrong with this method. You see the empty space at the bottom because you set the height of the scrollView contentSize to a larger value than the content. This is a question. Adjust the height according to the contents, empty space will go.

+1
source

Please try to get the actual size of the content from the current content.

the content must be some inherited class from UIView and has the property frame.size.width and frame.size.height .

you can use them to set the contentSize your UIScrollview for the current content while you are adding content to the UIScrollview .

+1
source

Yes. The dynamic size of scrollView can be adjusted using

 scroller.contentSize = CGSizeMake(1650, 2000); 

You can use the following property to set a dynamic frame for each page.

 [urScrollView scrollRectToVisible:frame animated:YES]; 

if you use pagingEnabled = YES for your scrollview

The next UIScrollViewDelegate delegate will adjust the page and content

 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ int page = urScrollView.contentOffset.x/urScrollView.frame.size.width; pageControl.currentPage = page; } //pager action - (IBAction)changePage:(id)sender{ int page = pageControl.currentPage; CGRect frame = urScrollView.frame; frame.origin.x = frame.size.width * page; frame.origin.y = 0; [urScrollView scrollRectToVisible:frame animated:YES]; } 

see sample application

0
source

Try it.

 - (void)viewDidLoad { float sizeOfContent = 0; UIView *lLast = [scrollView.subviews lastObject]; NSInteger wd = lLast.frame.origin.y; NSInteger ht = lLast.frame.size.height; sizeOfContent = wd+ht; scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent); } 
0
source

All Articles