Reputation: 4170
I want to create 10 UIViews with UIButtons and UILabels in a scrollview with paging enabled.
I want to reuse view on each page of scrollview. I don't want to create 10 views using loop.
How can I do it?
And another question. I want to give some animation effect on previous and next view while scrolling. so how can I identify the view?
Upvotes: 0
Views: 293
Reputation: 223
You can always use DMLazyScrollView library.
I'm using it frequently, and it's just work as you want :)
https://github.com/malcommac/DMLazyScrollView
Upvotes: 0
Reputation: 56
Definitely use UICollectionView. Pros?
EDIT: UICollectionView uses UIScrollViewDelegate as well.
Upvotes: 1
Reputation: 1474
I'd use 3 UIView
s - one for currently displaying view, one for previous and one for next view. While scrolling, I'd update frames of these views (or constraints), for example:
(-100, 0, 100, 100)
(0, 0, 100, 100)
(100, 0, 100, 100)
(0, 0, 100, 100)
(100, 0, 100, 100)
(200, 0, 100, 100)
These views are only for displaying purpose, so there is no need to identify the views themselves; I only need to have a current page index and also I need to update each view after page scrolling with content data basing on a data model, e.g. array elements with the following indexes: (currentPageIndex - 1)
, currentPageIndex
, (currentPageIndex + 1)
.
Upvotes: 0
Reputation: 1843
You can use UICollectionView in order to do that. You don't need to create your own flow layout - just use UICollectionViewFlowLayout, and change the item size and scroll direction.
Upvotes: 1